<?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/"
xmlns:series="http://unfoldingneurons.com/"
><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>Sun, 20 May 2012 22:40:48 +0000</lastBuildDate> <language>en</language> <sy:updatePeriod>hourly</sy:updatePeriod> <sy:updateFrequency>1</sy:updateFrequency> <generator>http://wordpress.org/?v=3.3.2</generator> <item><title>Adaptive&#160;Images</title><link>http://davidwalsh.name/adaptive-images</link> <comments>http://davidwalsh.name/adaptive-images#comments</comments> <pubDate>Wed, 21 Sep 2011 14:54:45 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=5296</guid> <description><![CDATA[The landscape of web continues to change as we get more and more devices that we need to support. One concern when creating websites that should accommodate all screen sizes is image size. The acceptable size for an image is not the same across devices, so we usually end up compromising image size and quality [...]<p><a
href="http://davidwalsh.name/adaptive-images">Adaptive&nbsp;Images</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></description> <content:encoded><![CDATA[<p>The landscape of web continues to change as we get more and more devices that we need to support.  One concern when creating websites that should accommodate all screen sizes is image size.  The acceptable size for an image is not the same across devices, so we usually end up compromising image size and quality on all devices;  not the optimal solution, of course.  Enter a solution called Adaptive Images, a PHP / .htaccess based solution for detecting screen size and delivering optimally sized images for the user&#8217;s device.</p><p><a
href="http://adaptive-images.com/" rel="nofollow"><img
src="http://davidwalsh.name/dw-content/adaptive-images.png" alt="Adaptive Images" /></a></p><div
class="actions"><a
href="http://adaptive-images.com/" rel="nofollow" class="demo">Adaptive Images</a><div
class="clear"></div></div><p>Adaptive images provides an outstanding set of instructions for customizing the images generated by PHP&#8217;s GD library, so you aren&#8217;t stuck with rubbish images.  Do yourself a favor and <a
href="http://adaptive-images.com/" rel="nofollow">check out Adaptive Images</a> &#8212; it could be the perfect solution for your website imagery needs.</p><p><a
href="http://davidwalsh.name/adaptive-images">Adaptive&nbsp;Images</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/adaptive-images/feed</wfw:commentRss> <slash:comments>5</slash:comments> </item> <item><title>Android Detection with JavaScript or&#160;PHP</title><link>http://davidwalsh.name/detect-android</link> <comments>http://davidwalsh.name/detect-android#comments</comments> <pubDate>Tue, 01 Mar 2011 14:42:18 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category> <category><![CDATA[JavaScript]]></category> <category><![CDATA[PHP]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=5180</guid> <description><![CDATA[I&#8217;ve noticed that two of my blog posts continue to get more popular each week:  iPad Detection with JavaScript or PHP and iPhone and iPad detection with JavaScript or PHP. What&#8217;s obvious is that Android development is a hot topic that will only grow.  Here are a few methods by which you can detect iOS&#8217; [...]<p><a
href="http://davidwalsh.name/detect-android">Android Detection with JavaScript or&nbsp;PHP</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></description> <content:encoded><![CDATA[<p>I&#8217;ve noticed that two of my blog posts continue to get more popular each week:  <a
href="http://davidwalsh.name/detect-ipad">iPad Detection with JavaScript or PHP</a> and <a
href="http://davidwalsh.name/detect-iphone">iPhone and iPad detection with JavaScript or PHP</a>.  What&#8217;s obvious is that Android development is a hot topic that will only grow.  Here are a few methods by which you can detect iOS&#8217; main competitor:  Android.</p><h2>The&nbsp;JavaScript</h2><p>Searching the user agent string for &#8220;Android&#8221; is the quickest method:</p><pre class="js">
var ua = navigator.userAgent.toLowerCase();
var isAndroid = ua.indexOf("android") > -1; //&#038;&#038; ua.indexOf("mobile");
if(isAndroid) {
	// Do something!
	// Redirect to Android-site?
	window.location = 'http://android.davidwalsh.name';
}
</pre><h2>The&nbsp;PHP</h2><p>Again, we&#8217;ll use PHP&#8217;s strstr function to search for Android in the user agent:</p><pre class="php">
$ua = strtolower($_SERVER['HTTP_USER_AGENT']);
if(stripos($ua,'android') !== false) { // &#038;&#038; stripos($ua,'mobile') !== false) {
	header('Location: http://android.davidwalsh.name');
	exit();
}
</pre><h2>Bonus!  .htaccess&nbsp;Detection</h2><p>We can even use .htaccess directives to detect and react to Android devices!</p><pre class="htaccess">
RewriteCond %{HTTP_USER_AGENT} ^.*Android.*$
RewriteRule ^(.*)$ http://android.davidwalsh.name [R=301]
</pre><p>And there you have it:  three different Android device detection!  Have fun with your mobile development!</p><p><a
href="http://davidwalsh.name/detect-android">Android Detection with JavaScript or&nbsp;PHP</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/detect-android/feed</wfw:commentRss> <slash:comments>44</slash:comments> </item> <item><title>Search Engine Friendly URLs with .htaccess and&#160;mod_rewrite</title><link>http://davidwalsh.name/htaccess-url</link> <comments>http://davidwalsh.name/htaccess-url#comments</comments> <pubDate>Mon, 11 Oct 2010 14:20:02 +0000</pubDate> <dc:creator>David Walsh</dc:creator> <category><![CDATA[.htaccess]]></category><guid
isPermaLink="false">http://davidwalsh.name/?p=5085</guid> <description><![CDATA[I was recently developing a PHP website that used mod_rewrite to make its URLs search engine friendly. Websites have been using mod_rewrite and .htaccess strategies to do this for years now and there are a 100 ways to accomplish the task. One issue that was occurring with this site was URLs without the a trailing [...]<p><a
href="http://davidwalsh.name/htaccess-url">Search Engine Friendly URLs with .htaccess and&nbsp;mod_rewrite</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></description> <content:encoded><![CDATA[<p>I was recently developing a PHP website that used mod_rewrite to make its URLs search engine friendly.  Websites have been using mod_rewrite and .htaccess strategies to do this for years now and there are a 100 ways to accomplish the task.  One issue that was occurring with this site was URLs without the a trailing slash would work, but URLs <em>with</em> a trailing slash would break (trigger a 404 error):</p><pre class="javascript">//works

http://mydomain.com/my-page

//breaks

http://mydomain.com/my-page/</pre><p>The original .htaccess source was:</p><pre class="htaccess">#adds ".php" to a URL that isn't a directory or a file
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) $1.php [L]</pre><p>The solution was simple:  an extra statement to accommodate for the trailing slash:</p><pre class="htaccess">#removes trailing slash if not a directory
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]

#adds ".php" to a URL that isn't a directory or a file
RewriteCond %{REQUEST_URI} !(\.[^./]+)$
RewriteCond %{REQUEST_fileNAME} !-d
RewriteCond %{REQUEST_fileNAME} !-f
RewriteRule (.*) $1.php [L]</pre><p>This method may be a bit inefficient as there are two redirects but it does the job.  Do you have a better solution?  If so, share it!</p><p><a
href="http://davidwalsh.name/htaccess-url">Search Engine Friendly URLs with .htaccess and&nbsp;mod_rewrite</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/htaccess-url/feed</wfw:commentRss> <slash:comments>14</slash:comments> </item> <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><a
href="http://davidwalsh.name/mod_rewrite-htaccess-godaddy">Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/mod_rewrite-htaccess-godaddy">Fixing mod_rewrite and .htaccess on GoDaddy&nbsp;Hosting</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/mod_rewrite-htaccess-godaddy/feed</wfw:commentRss> <slash:comments>38</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><a
href="http://davidwalsh.name/xpi-mime">Adding the XPI MIME Type for Firefox Extension&nbsp;Installs</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/xpi-mime">Adding the XPI MIME Type for Firefox Extension&nbsp;Installs</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></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><a
href="http://davidwalsh.name/yslow-htaccess">Improve Your YSlow Grade Using&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/yslow-htaccess">Improve Your YSlow Grade Using&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/yslow-htaccess/feed</wfw:commentRss> <slash:comments>31</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><a
href="http://davidwalsh.name/template-system-htaccess">Quickly Set Up a Templating System Using&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/template-system-htaccess">Quickly Set Up a Templating System Using&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/template-system-htaccess/feed</wfw:commentRss> <slash:comments>18</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><a
href="http://davidwalsh.name/check-module-presence-htaccess">Check For Module Presence in&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/check-module-presence-htaccess">Check For Module Presence in&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/check-module-presence-htaccess/feed</wfw:commentRss> <slash:comments>4</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><a
href="http://davidwalsh.name/htaccess-maintenance-page-redirect">.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/htaccess-maintenance-page-redirect">.htaccess &#8220;Down For Maintenance&#8221; Page&nbsp;Redirect</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/htaccess-maintenance-page-redirect/feed</wfw:commentRss> <slash:comments>31</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><a
href="http://davidwalsh.name/force-secure-ssl-htaccess">Force Secure (SSL) Pages With&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></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><a
href="http://davidwalsh.name/force-secure-ssl-htaccess">Force Secure (SSL) Pages With&nbsp;.htaccess</a> is a post from: <a
href="http://davidwalsh.name">David Walsh :: Legendary scribbles about JavaScript, HTML5, AJAX, PHP, CSS, and ∞.</a></p> ]]></content:encoded> <wfw:commentRss>http://davidwalsh.name/force-secure-ssl-htaccess/feed</wfw:commentRss> <slash:comments>11</slash:comments> </item> </channel> </rss>
<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Minified using disk: basic
Page Caching using disk: enhanced (User agent is rejected)
Database Caching 2/55 queries in 0.084 seconds using disk: basic
Object Caching 1436/1530 objects using disk: basic

Served from: davidwalsh.name @ 2012-05-23 22:36:57 -->
