<?xml version="1.0" encoding="UTF-8"?> <rss
version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:wfw="http://wellformedweb.org/CommentAPI/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
><channel><title>David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞. &#187; .htaccess</title> <atom:link href="http://davidwalsh.name/tutorials/htaccess/feed" rel="self" type="application/rss+xml" /><link>http://davidwalsh.name</link> <description>Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</description> <lastBuildDate>Thu, 02 Sep 2010 03:13:15 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.0.1</generator> <item><title>Fixing mod_rewrite and .htaccess on GoDaddy&#160;Hosting</title><link>http://davidwalsh.name/mod_rewrite-htaccess-godaddy</link> <comments>http://davidwalsh.name/mod_rewrite-htaccess-godaddy#comments</comments> <pubDate>Thu, 05 Nov 2009 13:24:52 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Apache / Server]]></category> <category><![CDATA[Hosting / Domain]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=4119</guid> <description><![CDATA[I recently launched a new website on GoDaddy shared hosting. The website required mod_rewrite for SEO-friendly URLs. GoDaddy provides mod_rewrite but every time I tried to hit a two-deep URL, I would get a 404 error. Here&#8217;s what I had: # Mod Rewrite Options +FollowSymLinks RewriteEngine On RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/mod_rewrite-htaccess-godaddy">Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/godaddy-hosting-curl' rel='bookmark' title='Permanent Link: GoDaddy Hosting Tip &#8211; Using CURL On GoDaddy Shared&nbsp;Hosting'>GoDaddy Hosting Tip &#8211; Using CURL On GoDaddy Shared&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li></ol>]]></description> <content:encoded><![CDATA[<p>I recently launched a new website on GoDaddy shared hosting.  The website required mod_rewrite for SEO-friendly URLs.  GoDaddy provides mod_rewrite but every time I tried to hit a two-deep URL, I would get a 404 error.  Here&#8217;s what I had:</p><pre class="htaccess"># Mod Rewrite
Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]</pre><p>The fix to this problem was to add the following directive before my mod_rewrite directives:</p><pre class="htaccess">#Fix Rewrite
Options -Multiviews</pre><p>Tada!  The URLs began working and the website&#8217;s SEO has taken off!</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/mod_rewrite-htaccess-godaddy">Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/godaddy-hosting-curl' rel='bookmark' title='Permanent Link: GoDaddy Hosting Tip &#8211; Using CURL On GoDaddy Shared&nbsp;Hosting'>GoDaddy Hosting Tip &#8211; Using CURL On GoDaddy Shared&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/mod_rewrite-htaccess-godaddy/feed</wfw:commentRss> <slash:comments>11</slash:comments> </item> <item><title>Adding the XPI MIME Type for Firefox Extension&#160;Installs</title><link>http://davidwalsh.name/xpi-mime</link> <comments>http://davidwalsh.name/xpi-mime#comments</comments> <pubDate>Tue, 12 May 2009 13:04:43 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Browsers]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=2403</guid> <description><![CDATA[Yesterday I posted version 0.1 of the David Walsh Blog Toolbar for Firefox. Unfortunately that led to an awkward conversation with my .htaccess file. .htaccess: I have no idea what to do with this. me: I want the toolbar to install when they request this file. .htaccess: Well, how am I supposed to do that? [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/xpi-mime">Adding the XPI MIME Type for Firefox Extension&nbsp;Installs</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/firefox-extension-template' rel='bookmark' title='Permanent Link: Firefox Extension&nbsp;Template'>Firefox Extension&nbsp;Template</a></li><li><a
href='http://davidwalsh.name/package-xpi-zip' rel='bookmark' title='Permanent Link: Package Your Firefox Extension into an&nbsp;XPI'>Package Your Firefox Extension into an&nbsp;XPI</a></li><li><a
href='http://davidwalsh.name/firefox-toolbar' rel='bookmark' title='Permanent Link: David Walsh Blog Firefox&nbsp;Toolbar'>David Walsh Blog Firefox&nbsp;Toolbar</a></li><li><a
href='http://davidwalsh.name/firefox-plugins' rel='bookmark' title='Permanent Link: My Firefox&nbsp;Plugins'>My Firefox&nbsp;Plugins</a></li><li><a
href='http://davidwalsh.name/mootools-documentation' rel='bookmark' title='Permanent Link: MooTools Documentation Search&nbsp;Favelet'>MooTools Documentation Search&nbsp;Favelet</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Yesterday I posted version 0.1 of the <a
href="http://davidwalsh.name/firefox-toolbar">David Walsh Blog Toolbar</a> for Firefox.  Unfortunately that led to an awkward conversation with my <span
class="file">.htaccess</span> file.</p><blockquote
style="border-color:#ccc;background:#eee;color:#000;"><strong>.htaccess: </strong>I have no idea what to do with this.</blockquote><blockquote><strong>me: </strong>I want the toolbar to install when they request this file.</blockquote><blockquote
style="border-color:#ccc;background:#eee;color:#000;"><strong>.htaccess: </strong>Well, how am I supposed to do that?</blockquote><blockquote><strong>me: </strong>OMG! You don&#8217;t know?!</blockquote><blockquote
style="border-color:#ccc;background:#eee;color:#000;"><strong>.htaccess: </strong>No, just like you didn&#8217;t know how to create a Firefox extension before you did the research.</blockquote><blockquote><strong>me:</strong> Good point.  When can you research and start serving it up?</blockquote><blockquote
style="border-color:#ccc;background:#eee;color:#000;"><strong>.htaccess: </strong>I can&#8217;t research.  I&#8217;m a file.</blockquote><blockquote><strong>me: </strong>Oh.  So I just need to figure things out for you again?</blockquote><blockquote
style="border-color:#ccc;background:#eee;color:#000;"><strong>.htaccess: </strong>You never pay attention to me anymore&#8230;</blockquote><p>That went on for quite a while but the moral of the story is that if you want your server to handle XPI files correctly, you need to add the following to your <span
class="file">.htaccess</span> file:</p><pre class="js">
AddType application/x-xpinstall .xpi
</pre><p>If you don&#8217;t add the above directive, Firefox will open the file as plain text which is an ugly mess.</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/xpi-mime">Adding the XPI MIME Type for Firefox Extension&nbsp;Installs</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/firefox-extension-template' rel='bookmark' title='Permanent Link: Firefox Extension&nbsp;Template'>Firefox Extension&nbsp;Template</a></li><li><a
href='http://davidwalsh.name/package-xpi-zip' rel='bookmark' title='Permanent Link: Package Your Firefox Extension into an&nbsp;XPI'>Package Your Firefox Extension into an&nbsp;XPI</a></li><li><a
href='http://davidwalsh.name/firefox-toolbar' rel='bookmark' title='Permanent Link: David Walsh Blog Firefox&nbsp;Toolbar'>David Walsh Blog Firefox&nbsp;Toolbar</a></li><li><a
href='http://davidwalsh.name/firefox-plugins' rel='bookmark' title='Permanent Link: My Firefox&nbsp;Plugins'>My Firefox&nbsp;Plugins</a></li><li><a
href='http://davidwalsh.name/mootools-documentation' rel='bookmark' title='Permanent Link: MooTools Documentation Search&nbsp;Favelet'>MooTools Documentation Search&nbsp;Favelet</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/xpi-mime/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Improve Your YSlow Grade Using&#160;.htaccess</title><link>http://davidwalsh.name/yslow-htaccess</link> <comments>http://davidwalsh.name/yslow-htaccess#comments</comments> <pubDate>Tue, 14 Apr 2009 12:34:48 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=2085</guid> <description><![CDATA[This post was authored by Eric Wendelin. To learn more about Eric, click here. A significant part of your YSlow grade depends on how well your site utilizes optimal caching techniques. By editing your .htaccess file, you can increase your YSlow score by 20 points or so in just 3 minutes! Quick Intro to&#160;Caching Caching [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/yslow-htaccess">Improve Your YSlow Grade Using&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/hide-your-htaccess-settings-using-htaccess' rel='bookmark' title='Permanent Link: Hide Your .htaccess Settings Using …&nbsp;.htaccess'>Hide Your .htaccess Settings Using …&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/php-header-mime' rel='bookmark' title='Permanent Link: PHP Headers and Popular Mime&nbsp;Types'>PHP Headers and Popular Mime&nbsp;Types</a></li><li><a
href='http://davidwalsh.name/php-force-download' rel='bookmark' title='Permanent Link: PHP Force Download &#8211; Keep Track of What&#8217;s Going&nbsp;Down'>PHP Force Download &#8211; Keep Track of What&#8217;s Going&nbsp;Down</a></li><li><a
href='http://davidwalsh.name/custom-page-extensions-htaccess' rel='bookmark' title='Permanent Link: Advanced Branding &#8211; Give Your Pages A Custom Extension Using .htaccess&nbsp;SetHandler'>Advanced Branding &#8211; Give Your Pages A Custom Extension Using .htaccess&nbsp;SetHandler</a></li></ol>]]></description> <content:encoded><![CDATA[<div
class="guest-blogger-top"><p>This post was authored by <a
href="http://www.eriwen.com/" target="_blank" rel="nofollow">Eric Wendelin</a>.  To learn more about Eric, <a
href="#bio-eric">click here</a>.</p></div><p>A significant part of your YSlow grade depends on how well your site utilizes optimal caching techniques. By editing your <span
class="file">.htaccess</span> file, you can increase your <a
href="http://developer.yahoo.com/yslow/">YSlow</a> score by 20 points or so in just 3 minutes!</p><h2>Quick Intro to&nbsp;Caching</h2><p>Caching is a browser feature that allows storage of certain types of web files on the client-side. In most cases, we want to have our clients cache our static files like HTML and CSS so that our website is <em>faster after the first request</em>.</p><p>Browser caching mainly depends on two things: the headers you send in an HTTP response and the browser your client is using.</p><p><img
src="http://eriwen.com/images/304.png" alt="304 Means wasted time" /></p><p>There are a couple of things a browser can do when caching depending on the headers used.</p><ol><li>It can <em>check back on every request</em>, and servers will reply with a HTTP status 304 (Not Modified) if the file is indeed the same.</li><li>Only ask the server for the file when the cached one has expired.</li></ol><p>The latter case is better for performance because the browser <em>doesn&#8217;t even ask</em> and therefore saves a lot of <acronym
title="HyperText Transfer Protocol">HTTP</acronym> requests.</p><h2>Setting the Expires&nbsp;Header</h2><p>One of the best things we can do to ensure good cache-ability is set a <a
href="http://developer.yahoo.com/performance/rules.html#expires">far future Expires header</a>:</p><pre class="xml">
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"&gt;
Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT"
&lt;/FilesMatch&gt;
</pre><p>Note here that if your site changes a lot, you&#8217;ll need to rename/version your files or get clever with your ETags to keep users up-to-date. If you Firebug my site, <a
href="http://eriwen.com/" title="Eric Wendelin's Blog">eriwen.com</a>, you&#8217;ll see that I do just that. Stay tuned there for a script that can help you automate this.</p><h2>Controlling Those&nbsp;ETags</h2><p>ETags are difficult because they <em>take precedence for caching</em> in most browsers. You can change all the headers you want, but if the ETag associated with a file is always the same, caching will never work how you expect. In most situations, <em>you should turn your ETag headers off</em>.</p><pre class="xml">
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"&gt;
Header unset ETag
FileETag None
&lt;/FilesMatch&gt;
</pre><p>Yes, you can combine the two snippets:</p><pre class="xml">
&lt;FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$"&gt;
Header set Expires "Thu, 15 Apr 2012 20:00:00 GMT"
Header unset ETag
FileETag None
&lt;/FilesMatch&gt;
</pre><h2>Testing Your New&nbsp;Settings</h2><p>The best way to see what&#8217;s going on is to check the &#8220;Net&#8221; tab in <a
href="http://getfirebug.com">Firebug</a>. You can use a tool like the <a
href="https://addons.mozilla.org/en-US/firefox/addon/3829">Live HTTP Headers</a> Firefox extension (there&#8217;s also one for IE) to verify what headers are being sent. NOTE: If you refresh the page instead of clicking a link, Firefox will recheck all files it has cached. <em>This is not the test you&#8217;re looking for.</em></p><p>You want to make sure everything is occurring exactly as you intended. Now is the time to bring out your inner control-freak.</p><h2>Conclusion</h2><p>These are just 2 simple ways to maximize caching (and therefore speed) of your site. There are <a
href="http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html">lots of other headers</a> to play with, but I find that these two give the biggest bang for your buck. Share your caching tricks in the comments!</p><a
title="bio-eric" name="bio-eric" id="bio-eric"></a><div
class="guest-blogger-bio"> <img
src="http://davidwalsh.name/dw-content/eric-wendelin.jpg" class="image" /><h2>About Eric&nbsp;Wendelin</h2><p> Eric Wendelin is a software engineer for Sun Microsystems. When he&#8217;s not doing super-secret programming for Sun, he plays indoor soccer, playing Wii with his friends, and cheering on the Colorado Avalanche. He also writes a blog on JavaScript, CSS, Java, and Productivity at <a
href="http://eriwen.com" target="_blank" rel="nofollow">eriwen.com</a></p></div><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/yslow-htaccess">Improve Your YSlow Grade Using&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/hide-your-htaccess-settings-using-htaccess' rel='bookmark' title='Permanent Link: Hide Your .htaccess Settings Using …&nbsp;.htaccess'>Hide Your .htaccess Settings Using …&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/php-header-mime' rel='bookmark' title='Permanent Link: PHP Headers and Popular Mime&nbsp;Types'>PHP Headers and Popular Mime&nbsp;Types</a></li><li><a
href='http://davidwalsh.name/php-force-download' rel='bookmark' title='Permanent Link: PHP Force Download &#8211; Keep Track of What&#8217;s Going&nbsp;Down'>PHP Force Download &#8211; Keep Track of What&#8217;s Going&nbsp;Down</a></li><li><a
href='http://davidwalsh.name/custom-page-extensions-htaccess' rel='bookmark' title='Permanent Link: Advanced Branding &#8211; Give Your Pages A Custom Extension Using .htaccess&nbsp;SetHandler'>Advanced Branding &#8211; Give Your Pages A Custom Extension Using .htaccess&nbsp;SetHandler</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/yslow-htaccess/feed</wfw:commentRss> <slash:comments>32</slash:comments> </item> <item><title>Quickly Set Up a Templating System Using&#160;.htaccess</title><link>http://davidwalsh.name/template-system-htaccess</link> <comments>http://davidwalsh.name/template-system-htaccess#comments</comments> <pubDate>Mon, 17 Nov 2008 13:47:27 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=620</guid> <description><![CDATA[Setting up a website capable of easy template switching probably sounds difficult. When I first thought about building a templating system, it felt like a pretty daunting task. After tinkering around for a few days, I found a way that would allow me to switch templates by simply changing a .htaccess directive. The Folder&#160;Structure + [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/template-system-htaccess">Quickly Set Up a Templating System Using&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/htaccess-301s-change-domains-but-keep-traffic' rel='bookmark' title='Permanent Link: Change Domains But Keep Your Traffic &#8211; .htaccess&nbsp;301s'>Change Domains But Keep Your Traffic &#8211; .htaccess&nbsp;301s</a></li><li><a
href='http://davidwalsh.name/organized-short-folder-structure-mod_rewrite' rel='bookmark' title='Permanent Link: Organized, Short Folder Structure Using&nbsp;mod_rewrite'>Organized, Short Folder Structure Using&nbsp;mod_rewrite</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Setting up a website capable of easy template switching probably sounds difficult.  When I first thought about building a templating system, it felt like a pretty daunting task.  After tinkering around for a few days, I found a way that would allow me to switch templates by simply changing a <span
class="file">.htaccess</span> directive.</p><h2>The Folder&nbsp;Structure</h2><pre  class="js">
+ root
	+ templates
		+ version1
			- css
			- graphics
			- js
		+ version2
			- css
			- graphics
			- js
		+ version3
			- css
			- graphics
			- js
</pre><p>Note that the different templates go in different folders within the temlpates folder &#8212; that includes template graphics, CSS styles, and JavaScript files.  If any other types of files are specific to your template, you may add a directive to make them template-specific as well.</p><h2>The .htaccess&nbsp;Directives</h2><pre  class="js">
RewriteRule ^css/(.*)			/templates/version2/css/$1
RewriteRule ^graphics/(.*)		/templates/version2/graphics/$1
RewriteRule ^js/(.*)				/templates/version2/js/$1
</pre><p>The <span
class="file">.htaccess</span> directives change the request paths from the root level to the current template&#8217;s folder.  Essentially, to switch themes, all you need to do is change the template folder in the <span
class="file">.htaccess</span> file.</p><h2>Referencing&nbsp;Files</h2><pre  class="html">
	
	&lt;script type="text/javascript" src="/js/moo-121.js"&gt;&lt;/script&gt;
	&lt;link rel="stylesheet" type="text/css" href="/css/theme.css" /&gt;
	
	&lt;!-- further in the page... --&gt;
	
	&lt;img src="/graphics/logo.jpg" /&gt;
	
	
</pre><p>Since the <span
class="file">.htaccess</span> directives above are changing the paths of the images, we can simply refer to the JavaScript, css, and graphics files by the shorter path.  This way you don&#8217;t reveal your file structure, you get to keep your code shorter, and switching templates is extremely easy.</p><p>What are your thoughts?  Is there a better way to go about this?  If so, please share.</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/template-system-htaccess">Quickly Set Up a Templating System Using&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/htaccess-301s-change-domains-but-keep-traffic' rel='bookmark' title='Permanent Link: Change Domains But Keep Your Traffic &#8211; .htaccess&nbsp;301s'>Change Domains But Keep Your Traffic &#8211; .htaccess&nbsp;301s</a></li><li><a
href='http://davidwalsh.name/organized-short-folder-structure-mod_rewrite' rel='bookmark' title='Permanent Link: Organized, Short Folder Structure Using&nbsp;mod_rewrite'>Organized, Short Folder Structure Using&nbsp;mod_rewrite</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/template-system-htaccess/feed</wfw:commentRss> <slash:comments>19</slash:comments> </item> <item><title>Check For Module Presence in&#160;.htaccess</title><link>http://davidwalsh.name/check-module-presence-htaccess</link> <comments>http://davidwalsh.name/check-module-presence-htaccess#comments</comments> <pubDate>Fri, 07 Nov 2008 13:44:01 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=748</guid> <description><![CDATA[One of my favorite Apache modules is mod_rewrite. mod_rewrite allows me to manipulate page URLs so that I can search engine friendly URLs. Not every Apache server has the mod_rewrite module installed so you will want to add a conditional statement within your .htaccess file to make sure it&#8217;s there. The&#160;.htaccess #Wordpress's .htaccess code &#60;IfModule [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/check-module-presence-htaccess">Check For Module Presence in&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li></ol>]]></description> <content:encoded><![CDATA[<p>One of my favorite Apache modules is mod_rewrite.  mod_rewrite allows me to manipulate page URLs so that I can search engine friendly URLs.  Not every Apache server has the mod_rewrite module installed so you will want to add a conditional statement within your <span
class="file">.htaccess</span> file to make sure it&#8217;s there.</p><h2>The&nbsp;.htaccess</h2><pre  class="js">
#Wordpress's .htaccess code
&lt;IfModule mod_rewrite.c&gt;
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
&lt;/IfModule&gt;
</pre><p>If the &#8220;mod_rewrite.c&#8221; module is present, that means that mod_rewrite is available and will be used.  If not, the mod_rewrite code will be ignored.  Using this conditional statement will prevent 500 Internal Server Errors.</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/check-module-presence-htaccess">Check For Module Presence in&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/check-module-presence-htaccess/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>.htaccess &#8220;Down For Maintenance&#8221; Page&#160;Redirect</title><link>http://davidwalsh.name/htaccess-maintenance-page-redirect</link> <comments>http://davidwalsh.name/htaccess-maintenance-page-redirect#comments</comments> <pubDate>Thu, 22 May 2008 12:59:17 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Security]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=245</guid> <description><![CDATA[I recently needed to move one website from a shared web host to our internal server. After some discussion, we decided to simply add a &#8220;Site Down For Maintenance&#8221; page to the site to prevent users from submitting orders during the hosting change. Using the following .htaccess code snippet, we were able to send all [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/htaccess-maintenance-page-redirect">.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/force-secure-ssl-htaccess' rel='bookmark' title='Permanent Link: Force Secure (SSL) Pages With&nbsp;.htaccess'>Force Secure (SSL) Pages With&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/advanced-htaccess-security-block-unwanted-referrers' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Unwanted&nbsp;Referrers'>Advanced .htaccess Security &#8211; Block Unwanted&nbsp;Referrers</a></li></ol>]]></description> <content:encoded><![CDATA[<p>I recently needed to move one website from a shared web host to our internal server.  After some discussion, we decided to simply add a &#8220;Site Down For Maintenance&#8221; page to the site to prevent users from submitting orders during the hosting change.  Using the following <span
class="file">.htaccess</span> code snippet, we were able to send all users to a <span
class="file">maintenance.html</span> page no matter which page they requested:</p><pre  class="js">
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
</pre><p>Once we posted the <span
class="file">maintenance.html</span> page and <span
class="file">.htaccess</span> code on both the old hosting environment AND new hosting environment, we switched the DNS settings.  Before making the switch, we had ported the website&#8217;s code to a &#8220;utility&#8221; domain and made adjustments so that the website would function well in the new hosting environment.  Now that the DNS had been changed, we wanted to make sure that the website would function well on the new domain within the new hosting environment.  Unfortunately the code above blocks EVERYONE from accessing any file besides the <span
class="file">maintenance.html</span> file.  Fortunately my gifted IT team had the answer:</p><pre  class="js">
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} !^11\.111\.111\.111
RewriteCond %{REQUEST_URI} !^/maintenance\.html$
RewriteRule ^(.*)$ http://domain.com/maintenance.html [R=307,L]
</pre><p>The above code sends all users to <span
class="file">maintenance.html</span> EXCEPT those with the specified IP, which just so happened to be us.  We got to test the website while others were locked out. When we were satisfied with the website, we removed the <span
class="file">.htaccess</span> code and the site was back up immediately!</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/htaccess-maintenance-page-redirect">.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/force-secure-ssl-htaccess' rel='bookmark' title='Permanent Link: Force Secure (SSL) Pages With&nbsp;.htaccess'>Force Secure (SSL) Pages With&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/advanced-htaccess-security-block-unwanted-referrers' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Unwanted&nbsp;Referrers'>Advanced .htaccess Security &#8211; Block Unwanted&nbsp;Referrers</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/htaccess-maintenance-page-redirect/feed</wfw:commentRss> <slash:comments>23</slash:comments> </item> <item><title>Force Secure (SSL) Pages With&#160;.htaccess</title><link>http://davidwalsh.name/force-secure-ssl-htaccess</link> <comments>http://davidwalsh.name/force-secure-ssl-htaccess#comments</comments> <pubDate>Fri, 09 May 2008 12:55:05 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Security]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=248</guid> <description><![CDATA[A while back, I shared a method for forcing a secure page using PHP. What if you want to force SSL (https://) on an entire website though? You don&#8217;t want to have to put force-SSL PHP code on every page, right? Well, the website&#8217;s .htaccess file comes to the rescue. The .htaccess&#160;Code RewriteEngine On RewriteCond [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/force-secure-ssl-htaccess">Force Secure (SSL) Pages With&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/force-secure-page-php' rel='bookmark' title='Permanent Link: Force A Secure Page Using&nbsp;PHP'>Force A Secure Page Using&nbsp;PHP</a></li><li><a
href='http://davidwalsh.name/secure-ssl-google-analytics' rel='bookmark' title='Permanent Link: Secure (SSL) Google&nbsp;Analytics'>Secure (SSL) Google&nbsp;Analytics</a></li><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li></ol>]]></description> <content:encoded><![CDATA[<p>A while back, I shared a method for <a
href="http://davidwalsh.name/force-secure-page-php">forcing a secure page using PHP</a>.  What if you want to force SSL <em>(https://)</em> on an entire website though?  You don&#8217;t want to have to put force-SSL PHP code on every page, right?  Well, the website&#8217;s <span
class="file">.htaccess</span> file comes to the rescue.</p><h2>The .htaccess&nbsp;Code</h2><pre  class="js">
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://domain.com/$1 [R,L]</pre><p> Obviously, you&#8217;ll want to change &#8220;domain.com&#8221; to your domain.  Another short snippet of code that has a big impact on your website!</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/force-secure-ssl-htaccess">Force Secure (SSL) Pages With&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/force-secure-page-php' rel='bookmark' title='Permanent Link: Force A Secure Page Using&nbsp;PHP'>Force A Secure Page Using&nbsp;PHP</a></li><li><a
href='http://davidwalsh.name/secure-ssl-google-analytics' rel='bookmark' title='Permanent Link: Secure (SSL) Google&nbsp;Analytics'>Secure (SSL) Google&nbsp;Analytics</a></li><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/no-www-using-htaccess-file' rel='bookmark' title='Permanent Link: No WWW Using&nbsp;.htaccess'>No WWW Using&nbsp;.htaccess</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/force-secure-ssl-htaccess/feed</wfw:commentRss> <slash:comments>7</slash:comments> </item> <item><title>Password Protect a Directory Using&#160;.htaccess</title><link>http://davidwalsh.name/password-protect-directory-using-htaccess</link> <comments>http://davidwalsh.name/password-protect-directory-using-htaccess#comments</comments> <pubDate>Fri, 18 Apr 2008 12:46:23 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Security]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=265</guid> <description><![CDATA[Protecting files on your website from unauthorized users can be very important. Even more important is the method by which you accomplish this task. You could use PHP to listen for login authorization information on each page, but that doesn&#8217;t protect your images, documents, and other media, does it? That&#8217;s why I&#8217;ve found the .htaccess [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/password-protect-directory-using-htaccess">Password Protect a Directory Using&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/prevent-directory-listings-with-htaccess' rel='bookmark' title='Permanent Link: Prevent Directory Listings With&nbsp;.htaccess'>Prevent Directory Listings With&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/hide-your-htaccess-settings-using-htaccess' rel='bookmark' title='Permanent Link: Hide Your .htaccess Settings Using …&nbsp;.htaccess'>Hide Your .htaccess Settings Using …&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/directory-index-homepage-htaccess' rel='bookmark' title='Permanent Link: Set Your Directory Index (Homepage) Using&nbsp;.htaccess'>Set Your Directory Index (Homepage) Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/robots-txt' rel='bookmark' title='Permanent Link: Disallow Robots Using&nbsp;Robots.txt'>Disallow Robots Using&nbsp;Robots.txt</a></li></ol>]]></description> <content:encoded><![CDATA[<p>Protecting files on your website from unauthorized users can be very important.  Even more important is the method by which you accomplish this task.  You could use PHP to listen for login authorization information on each page, but that doesn&#8217;t protect your images, documents, and other media, does it?  That&#8217;s why I&#8217;ve found the <span
class="file">.htaccess</span> method of protecting files and directories the most reliable.  Oh, and it&#8217;s easy too!</p><p>The system requires two files &#8212; the <span
class="file">.htaccess</span> file and <span
class="file">.htpasswd file</span>.</p><h2>The .htaccess&nbsp;Code</h2><pre  class="js">AuthType Basic
AuthName "restricted area"
AuthUserFile /home/davidwalsh/html/protect-me-dir/.htpasswd
require valid-user</pre><p>The above code protects a directory called &#8220;protect-me-dir&#8221; at root level.  The &#8220;AuthUserFile&#8221; value is always specific to your hosting configuration.  If you don&#8217;t know what the value should be, do a <span
class="function">phpinfo()</span> and find the <span
class="parameter">DOCUMENT_ROOT</span> value.</p><h2>The .htpasswd&nbsp;Code</h2><pre  class="js">davidwalsh:daWHfZrDLB88.
rodstewart:roFulYxC2.8ws
cssexpert:csmnmq.M8T5ho</pre><p>The <span
class="file">.htpasswd</span> file contains the usernames and passwords of allowed users.  One per line.  The passwords are MD5&#8242;d for security purposes.</p><p>To generate encrypted passwords for your <span
class="file">.htpasswd</span> file, you can use my <a
href="http://davidwalsh.name/htaccess-username-password-generator">.htaccess password generator</a>.</p><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/password-protect-directory-using-htaccess">Password Protect a Directory Using&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/prevent-directory-listings-with-htaccess' rel='bookmark' title='Permanent Link: Prevent Directory Listings With&nbsp;.htaccess'>Prevent Directory Listings With&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/hide-your-htaccess-settings-using-htaccess' rel='bookmark' title='Permanent Link: Hide Your .htaccess Settings Using …&nbsp;.htaccess'>Hide Your .htaccess Settings Using …&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/directory-index-homepage-htaccess' rel='bookmark' title='Permanent Link: Set Your Directory Index (Homepage) Using&nbsp;.htaccess'>Set Your Directory Index (Homepage) Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/htaccess-security-include-files' rel='bookmark' title='Permanent Link: Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess'>Advanced .htaccess Security &#8211; Block Access to Include Files Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/robots-txt' rel='bookmark' title='Permanent Link: Disallow Robots Using&nbsp;Robots.txt'>Disallow Robots Using&nbsp;Robots.txt</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/password-protect-directory-using-htaccess/feed</wfw:commentRss> <slash:comments>20</slash:comments> </item> <item><title>No WWW Using&#160;.htaccess</title><link>http://davidwalsh.name/no-www-using-htaccess-file</link> <comments>http://davidwalsh.name/no-www-using-htaccess-file#comments</comments> <pubDate>Tue, 08 Jan 2008 13:55:02 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Google]]></category><guid
isPermaLink="false">http://davidwalsh.name/no-www-using-htaccess-file/</guid> <description><![CDATA[There are some clear benefits to removing the &#8220;www&#8221; from your URLs: Shorter URLs Prevention of Google search engine penalties for duplicate content Less bandwidth usage if you have many links per page Luckily, removing the WWW from your page URLs (and subsequent Google listings) can be done inside your .htaccess file so that you [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/no-www-using-htaccess-file">No WWW Using&nbsp;.htaccess</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/force-secure-ssl-htaccess' rel='bookmark' title='Permanent Link: Force Secure (SSL) Pages With&nbsp;.htaccess'>Force Secure (SSL) Pages With&nbsp;.htaccess</a></li></ol>]]></description> <content:encoded><![CDATA[<p>There are some clear benefits to removing the &#8220;www&#8221; from your URLs:</p><ul><li>Shorter URLs</li><li>Prevention of Google search engine penalties for duplicate content</li><li>Less bandwidth usage if you have many links per page</li></ul><p>Luckily, removing the WWW from your page URLs (and subsequent Google listings) can be done inside your <span
class="file">.htaccess</span> file so that you wont have to go into every page on your website and remove the &#8220;www&#8221; from your anchors.</p><h2>The .htaccess&nbsp;Code</h2><pre  class="js">RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^domain.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]</pre><p>Conversely, if you&#8217;d prefer to use &#8220;www&#8221; in all of your URLs, you can code:</p><pre  class="js">RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^www.domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]</pre><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/no-www-using-htaccess-file">No WWW Using&nbsp;.htaccess</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/htaccess-maintenance-page-redirect' rel='bookmark' title='Permanent Link: .htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect'>.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/force-secure-ssl-htaccess' rel='bookmark' title='Permanent Link: Force Secure (SSL) Pages With&nbsp;.htaccess'>Force Secure (SSL) Pages With&nbsp;.htaccess</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/no-www-using-htaccess-file/feed</wfw:commentRss> <slash:comments>16</slash:comments> </item> <item><title>Organized, Short Folder Structure Using&#160;mod_rewrite</title><link>http://davidwalsh.name/organized-short-folder-structure-mod_rewrite</link> <comments>http://davidwalsh.name/organized-short-folder-structure-mod_rewrite#comments</comments> <pubDate>Wed, 07 Nov 2007 13:52:25 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[Optimization]]></category><guid
isPermaLink="false">http://davidwalsh.name/organized-short-folder-structure-mod_rewrite/</guid> <description><![CDATA[I tend to be over-organized when I create the folder structure of my customers&#8217; websites. I like using descriptive file and folder names for a number of reasons: Search engine friendly URLS and image names (for image searches) Descriptive file names give users a &#8220;preview&#8221; of the linked page in the status bar (if the [...]<p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/organized-short-folder-structure-mod_rewrite">Organized, Short Folder Structure Using&nbsp;mod_rewrite</a></p>Related posts:<ol><li><a
href='http://davidwalsh.name/template-system-htaccess' rel='bookmark' title='Permanent Link: Quickly Set Up a Templating System Using&nbsp;.htaccess'>Quickly Set Up a Templating System Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li></ol>]]></description> <content:encoded><![CDATA[<p>I tend to be over-organized when I create the folder structure of my customers&#8217; websites.  I like using descriptive file and folder names for a number of reasons:</p><ul><li>Search engine friendly URLS and image names (for image searches)</li><li>Descriptive file names give users a &#8220;preview&#8221; of the linked page in the status bar (if the anchor text isn&#8217;t descriptive enough or the link is an image)</li><li>I want to be able to tell what a file is when I see the file name</li></ul><p>One problem with my method is that long folder names can be annoying to type and can bloat your pages resulting in ugly load times.  I use the power of mod_rewrite to shorten paths to files I reference most, image files.</p><h2>The&nbsp;XHTML</h2><pre  class="html" rows="2" cols="40"><img src="/graphics/icons/small/icon.jpg" width="10" height="10" alt="Image" /><br /></pre><p>becomes&#8230;</p><pre  class="html" rows="2" cols="40"><img src="/gis/icon.jpg" width="10" height="10" alt="Image" /><br /></pre><h2>The mod_rewrite&nbsp;.htaccess</h2><pre  class="js" rows="2" cols="40">RewriteEngine On
RewriteRule ^gis/(.*)$ /graphics/icons/small/$1 [L]</pre><p><strong>Follow Me!</strong> <a
href="http://twitter.com/davidwalshblog">Twitter</a> | <a
href="http://www.facebook.com/#!/pages/David-Walsh-Blog/186644584869">Facebook</a> | <a
href="http://www.linkedin.com/in/davidjameswalsh">LinkedIn</a> | <a
href="http://mootools.net/forge/profile/davidwalsh">MooTools Forge.</a><br/><br/>Full David Walsh Blog Post: <a
href="http://davidwalsh.name/organized-short-folder-structure-mod_rewrite">Organized, Short Folder Structure Using&nbsp;mod_rewrite</a></p><p>Related posts:<ol><li><a
href='http://davidwalsh.name/template-system-htaccess' rel='bookmark' title='Permanent Link: Quickly Set Up a Templating System Using&nbsp;.htaccess'>Quickly Set Up a Templating System Using&nbsp;.htaccess</a></li><li><a
href='http://davidwalsh.name/mod_rewrite-htaccess-godaddy' rel='bookmark' title='Permanent Link: Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting'>Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a></li><li><a
href='http://davidwalsh.name/prevent-image-hotlinking' rel='bookmark' title='Permanent Link: Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite'>Prevent Image Hotlinking With .htaccess and&nbsp;mod_rewrite</a></li><li><a
href='http://davidwalsh.name/wordpress-htaccess-file-is-genius' rel='bookmark' title='Permanent Link: WordPress&#8217; .htaccess File Is&nbsp;Genius'>WordPress&#8217; .htaccess File Is&nbsp;Genius</a></li><li><a
href='http://davidwalsh.name/check-module-presence-htaccess' rel='bookmark' title='Permanent Link: Check For Module Presence in&nbsp;.htaccess'>Check For Module Presence in&nbsp;.htaccess</a></li></ol></p>]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/organized-short-folder-structure-mod_rewrite/feed</wfw:commentRss> <slash:comments>2</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk
Page Caching using disk (enhanced) (user agent is rejected)
Database Caching 142/390 queries in 2.871 seconds using disk

Served from: davidwalsh.name @ 2010-09-02 23:21:16 -->