<?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>the fancy part of the web &#187; apache</title>
	<atom:link href="http://blog.tolleiv.de/tag/apache/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.tolleiv.de</link>
	<description>is elsewhere - this is just about all sorts of web related work with a small factor of fanciness</description>
	<lastBuildDate>Fri, 03 Sep 2010 15:52:14 +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>Debugging mod_rewrite&#8230; my favorite way</title>
		<link>http://blog.tolleiv.de/2010/01/debugging-mod_rewrite/</link>
		<comments>http://blog.tolleiv.de/2010/01/debugging-mod_rewrite/#comments</comments>
		<pubDate>Sat, 23 Jan 2010 17:19:42 +0000</pubDate>
		<dc:creator>tolleiv</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[debug]]></category>

		<guid isPermaLink="false">http://blog.tolleiv.de/?p=299</guid>
		<description><![CDATA[Once a month someone is asking because he has issues to [...]]]></description>
			<content:encoded><![CDATA[<p>Once a month someone is asking because he has issues to get his mod_rewrite rules to do what he want&#8217;s. Writing the rules and the required RegEx for these rules is quite easy, but Apache still behaves strange every now and then and that&#8217;s where one of my favorite ways to &#8220;debug&#8221; mod_rewrite comes in very handy. And I felt that writing something is better than having a silent blog <img src='http://blog.tolleiv.de/wp-includes/images/smilies/icon_wink.gif' alt=';)' class='wp-smiley' /> </p>
<p>The following block is what it&#8217;s all about. It seems to have it&#8217;s origin on <a href="http://www.webmasterworld.com/forum92/5360.htm" target="_blank">WebmasterWorld</a> and <a href="http://www.latenightpc.com/blog/archives/2007/09/05/a-couple-ways-to-debug-mod_rewrite">Rob Russel&#8217;s Blog</a> and looks basically like this:</p>
<pre name="code" class="php">RewriteCond %{QUERY_STRING} !vardump
RewriteRule (.*) http://www.example.com/$1?vardump&amp;reqhost=%{HTTP_HOST} [R=301,L,QSA]</pre>
<p>Pretty easy and quite nice. The first line just prevents recursion, so that you&#8217;ll be able to see the first redirect and nothing else. The second line is where you can place in every information you&#8217;d like to check. The [R=301,L,QSA] makes sure that you can debug without interruption. The &#8220;R=301&#8243; makes sure the browser doesn&#8217;t start a second request, but tells him that the location was changed, the &#8220;QSA&#8221; makes sure that the querystring isn&#8217;t lost and the &#8220;L&#8221; prevents that your server performs other redirection rules.</p>
<p>As shown the first block already unveils some information and places it into the redirection URL, so you could use it to check what the value of HTTP_HOST is and you also know whether mod_rewrite works or not. This way you can debug every variable mod_rewrite offers and you can check environmental variables and results of the regular expressions.</p>
<p>If you&#8217;d like to know whether a specific RewriteCond is working or not just place it in that block and you&#8217;ll see if it&#8217;s still redirecting or not, like this (<a href="http://twitcode.org/Bb">via</a>):</p>
<pre name="code" class="php">RewriteCond %{QUERY_STRING} !vardump
RewriteCond %{HTTP:Accept-Language} ^de.*$
RewriteRule (.*) http://www.example.com/$1?vardump&amp;languageMatchedDE [R=301,L,QSA]</pre>
<p>Checking a regular expression from an RewriteCond looks like this (used on a server with a pretty strange setup for %{DOCUMENT_ROOT}):</p>
<pre name="code" class="php">RewriteCond %{QUERY_STRING} !vardump
RewriteCond %{REQUEST_FILENAME} ^(.*\/htdocs\/).*$
RewriteRule (.*) http://www.example.com/$1?vardump&amp;reqfilename=%1 [R=301,L,QSA]</pre>
<p>As you see that&#8217;s a pretty handy way to debug lot&#8217;s of mod_rewrite stuff, it helped me quite often and I hope it does the same for you <img src='http://blog.tolleiv.de/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
 <p>Feel free to Flattr this post at <a href="http://flattr.com/" title="Flattr" target="_blank">flattr.com</a>, if you like it.</p> <p><a href="http://flattr.com/" title="Flattr" target="_blank"><img src="http://blog.tolleiv.de/wp-content/plugins/flattrss/button-compact-static-100x17.png" alt="flattr this!"/></a></p>]]></content:encoded>
			<wfw:commentRss>http://blog.tolleiv.de/2010/01/debugging-mod_rewrite/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
