<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet href="/stylesheets/rss.css" type="text/css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>Eschew Obfuscation: Differences between RewriteRule in .htaccess and httpd.conf</title>
    <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Max Dunn's Personal Blog</description>
    <item>
      <title>Differences between RewriteRule in .htaccess and httpd.conf</title>
      <description>&lt;p&gt;This is probably obvious to people who know Apache well, but I just spent a half day struggling with the differences between RewriteRule in .htaccess and httpd.conf. I was assuming they would behave the same way, but there are slight differences:&lt;/p&gt;


	&lt;h2&gt;Differences&lt;/h2&gt;


	&lt;h4&gt;httpd.conf&lt;/h4&gt;


	&lt;ul&gt;
	&lt;li&gt;The request &lt;span class="caps"&gt;URI&lt;/span&gt; will have a leading slash&lt;/li&gt;
		&lt;li&gt;The leading slash needs to remain to find cached files&lt;/li&gt;
		&lt;li&gt;When using -f or !-f, it needs to have the document root on front&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h4&gt;.htaccess&lt;/h4&gt;


	&lt;ul&gt;
	&lt;li&gt;The request &lt;span class="caps"&gt;URI&lt;/span&gt; won&amp;#8217;t have a leading slash&lt;/li&gt;
		&lt;li&gt;Can&amp;#8217;t have a leading slash to find cached files&lt;/li&gt;
		&lt;li&gt;When using -f or !-f, don&amp;#8217;t use the document root&lt;/li&gt;
	&lt;/ul&gt;


	&lt;h2&gt;Examples&lt;/h2&gt;


	&lt;p&gt;Here is an example that looks in the public/cache directory for cached files:&lt;/p&gt;


	&lt;h4&gt;httpd.conf&lt;/h4&gt;


&lt;code&gt;
&lt;pre&gt;
RewriteRule ^/$ /cache/index.html [QSA]
RewriteRule ^/([^.]+)$ /cache/$1.html [QSA]
RewriteCond %{DOCUMENT_ROOT}%{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
&lt;/pre&gt;
&lt;/code&gt;

	&lt;h4&gt;.htaccess&lt;/h4&gt;


&lt;code&gt;
&lt;pre&gt;
RewriteRule ^$ cache/index.html [QSA]
RewriteRule ^([^.]+)$ cache/$1.html [QSA]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ dispatch.fcgi [QSA,L]
&lt;/pre&gt;
&lt;/code&gt;

	&lt;h4&gt;Rails&lt;/h4&gt;


	&lt;p&gt;Just to complete this example, add this line to a before_filter method in application.rb to have Rails cache files to this directory:&lt;/p&gt;


	&lt;pre&gt;&lt;code&gt;ApplicationController::page_cache_directory = "#{RAILS_ROOT}/public/cache"&lt;/code&gt;&lt;/pre&gt;</description>
      <pubDate>Fri, 12 Jan 2007 15:08:00 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:eef91d5b-d7e3-461f-86eb-6d243910764a</guid>
      <author>Max Dunn</author>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf</link>
      <category>Ruby on Rails</category>
      <category>Tech Tips</category>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Mark Sennott</title>
      <description>&lt;p&gt;I would add that query strings (the part after the ? in a URL) is part of the URI for matching purposes in .htaccess, but gets stripped off for httpd.conf rules.&lt;/p&gt;</description>
      <pubDate>Thu, 04 Sep 2008 12:00:39 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:fc6f7c80-2a51-43b6-9cbe-78d330423632</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-666</link>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Michael Houghton</title>
      <description>&lt;p&gt;Useful &amp;#8211; I reckoned the matches would be different but you&amp;#8217;ve still saved me an hour or two hunting down this information.&lt;/p&gt;</description>
      <pubDate>Thu, 07 Aug 2008 21:29:33 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:afae18b4-c535-4832-a497-702ee24105bd</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-659</link>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Greg</title>
      <description>&lt;p&gt;Thanks much! Fixed my problem!&lt;/p&gt;</description>
      <pubDate>Tue, 25 Mar 2008 14:00:30 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:1b09922e-6abe-449b-9a18-b6cff8c5ed5c</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-550</link>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Peter</title>
      <description>&lt;p&gt;Yep works good. Just spent 2 hours trying to figure out this issue!&lt;/p&gt;</description>
      <pubDate>Sun, 16 Dec 2007 12:34:55 -0800</pubDate>
      <guid isPermaLink="false">urn:uuid:a9842a8f-d8af-427e-8a9a-126fec861aa0</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-432</link>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Brian Adkins</title>
      <description>&lt;p&gt;Man, I wish I read this an hour ago! Thanks for the info.&lt;/p&gt;</description>
      <pubDate>Mon, 17 Sep 2007 15:38:06 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:b602c153-8ebe-46a4-abc0-bcaf7a1f8e56</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-331</link>
    </item>
    <item>
      <title>"Differences between RewriteRule in .htaccess and httpd.conf" by Gregory</title>
      <description>&lt;p&gt;Thanks for the tip! That&amp;#8217;s very useful to know.&lt;/p&gt;</description>
      <pubDate>Wed, 05 Sep 2007 04:08:55 -0700</pubDate>
      <guid isPermaLink="false">urn:uuid:cf9e8120-f90d-46aa-a8b9-250d919352d2</guid>
      <link>http://blog.maxdunn.com/articles/2007/01/12/differences-between-rewriterule-in-htaccess-and-httpd-conf#comment-321</link>
    </item>
  </channel>
</rss>
