<?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>Nomulous Blog &#187; Web</title>
	<atom:link href="http://nomulous.com/blog/tag/web/feed/" rel="self" type="application/rss+xml" />
	<link>http://nomulous.com/blog</link>
	<description>Caveat Lector</description>
	<lastBuildDate>Wed, 07 Sep 2011 21:04:42 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>How to avoid looping in mod_rewrite redirection</title>
		<link>http://nomulous.com/blog/how-to-avoid-looping-in-mod_rewrite-redirection/</link>
		<comments>http://nomulous.com/blog/how-to-avoid-looping-in-mod_rewrite-redirection/#comments</comments>
		<pubDate>Tue, 30 Jun 2009 05:40:54 +0000</pubDate>
		<dc:creator>nomulous</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[500]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[internal server error]]></category>
		<category><![CDATA[loop]]></category>
		<category><![CDATA[mod rewrite]]></category>
		<category><![CDATA[redirect]]></category>
		<category><![CDATA[regex]]></category>
		<category><![CDATA[request uri]]></category>
		<category><![CDATA[rewrite]]></category>
		<category><![CDATA[rewritecond]]></category>

		<guid isPermaLink="false">http://nomulous.com/blog/?p=66</guid>
		<description><![CDATA[When redirecting things to a new location that fits the original rewrite pattern, you end up with a recursive feedback loop and all you get is an error. If you specified a URL scheme and a domain in your rewrite (meaning that the redirection is visible to the browser) you&#8217;ll see the error in your [...]]]></description>
			<content:encoded><![CDATA[<p>When redirecting things to a new location that fits the original rewrite pattern, you end up with a recursive feedback loop and all you get is an error. If you specified a URL scheme and a domain in your rewrite (meaning that the redirection is visible to the browser) you&#8217;ll see the error in your browser saying something along the lines of &#8220;the page tried to redirect too many times&#8221;. Otherwise, the redirection will be internal, and you&#8217;ll get your server&#8217;s 500 Internal Server Error page.</p>
<p style="text-align: center;"><a href="http://nomulous.com/blog/wp-content/uploads/2009/06/redirect_loop_safari.png"><img class="aligncenter size-full wp-image-71" title="redirect_loop_safari" src="http://nomulous.com/blog/wp-content/uploads/2009/06/redirect_loop_safari.png" alt="redirect_loop_safari" width="478" height="236" /></a></p>
<p>So, how do you avoid it? Well, say you wanted to redirect some regex (regular expression) pattern to the your index page, say index.php, but it turns out that &#8220;index.php&#8221; actually matches your pattern, so index.php redirects to index.php which redirects to index.php, and so on, and so forth.</p>
<p>To prevent this, simply add a RewriteCond that checks the REQUEST_URI to make sure it doesn&#8217;t match the string that you redirect to. The following is an example.</p>
<p><code>RewriteCond %{REQUEST_URI} !^/?index.php$<br />
RewriteRule ^(regex|goes|here)$ /index.php</code></p>
<p>Just make sure the regex in the first part does <em>not</em> match any of the pages you want to redirect, and that&#8217;s it! You&#8217;re done.</p>
<p>Best of luck on getting this to work the way you want it to, and happy web developing!</p>
]]></content:encoded>
			<wfw:commentRss>http://nomulous.com/blog/how-to-avoid-looping-in-mod_rewrite-redirection/feed/</wfw:commentRss>
		<slash:comments>6</slash:comments>
		</item>
		<item>
		<title>A subdomain for each directory with .htaccess and some mod_rewrite wizardry</title>
		<link>http://nomulous.com/blog/a-subdomain-for-each-directory-with-htaccess-and-some-mod_rewrite-wizardry/</link>
		<comments>http://nomulous.com/blog/a-subdomain-for-each-directory-with-htaccess-and-some-mod_rewrite-wizardry/#comments</comments>
		<pubDate>Wed, 10 Jun 2009 20:27:35 +0000</pubDate>
		<dc:creator>nomulous</dc:creator>
				<category><![CDATA[Web]]></category>
		<category><![CDATA[apache]]></category>
		<category><![CDATA[development]]></category>
		<category><![CDATA[directory]]></category>
		<category><![CDATA[htaccess]]></category>
		<category><![CDATA[mod rewrite]]></category>
		<category><![CDATA[subdomain]]></category>

		<guid isPermaLink="false">http://nomulous.com/blog/?p=6</guid>
		<description><![CDATA[I don&#8217;t know how useful this will be to anyone, but I was playing around with my webserver a while back and because subdomains are pretty cool I thought I would figure out for myself how to do this. You may use either httpd.conf or an .htaccess at your document root. Make sure you have [...]]]></description>
			<content:encoded><![CDATA[<p>I don&#8217;t know how useful this will be to anyone, but I was playing around with my webserver a while back and because subdomains are pretty cool I thought I would figure out for myself how to do this.</p>
<p>You may use either httpd.conf or an .htaccess at your document root. </p>
<p>Make sure you have mod_rewrite turned on before you begin.<br />
<code>RewriteEngine On</code></p>
<p>First, use a RewriteCond like this to prevent redirection things like your favicon.ico that need to be available everywhere. Change this based on your setup.<br />
<code>RewriteCond %{REQUEST_URI} !^/(favicon.ico|images/.+|javascript/.*)$</code></p>
<p>Then, capture the subdomain in %1.<br />
<code>RewriteCond %{HTTP_HOST} ^(.+)\..+\..+$</code><br />
This next line just prevents looping by making sure the REQUEST_URI doesn&#8217;t match the what&#8217;s in %1. Don&#8217;t ask how it works.<br />
<code>RewriteCond %1,%{REQUEST_URI} !(^[^,]+),/\1.*</code></p>
<p>This checks to see if what we have in %1 is in fact a directory under the document root.<br />
<code>RewriteCond /your/document/root/%1 -d</code></p>
<p>And finally, redirect &#8216;/anything&#8217; to &#8216;/subdomain/anything&#8217;.<br />
<code>RewriteRule ^(.*)$ /%1/$1 [L]</code></p>
<p></p>
<p>And there we go, that should do it. All together, that&#8217;s:<br />
<code>RewriteCond %{REQUEST_URI} !^/(favicon.ico|images/.+|javascript/.*)$<br />
RewriteCond %{HTTP_HOST} ^(.+)\..+\..+$<br />
RewriteCond %1,%{REQUEST_URI} !(^[^,]+),/\1.*<br />
RewriteCond /your/document/root/%1 -d<br />
RewriteRule ^(.*)$ /%1/$1 [L]<br />
</code></p>
<p>Questions, comments, criticism, and other feedback are very welcome. If you have a better way of doing it, let me know!</p>
]]></content:encoded>
			<wfw:commentRss>http://nomulous.com/blog/a-subdomain-for-each-directory-with-htaccess-and-some-mod_rewrite-wizardry/feed/</wfw:commentRss>
		<slash:comments>7</slash:comments>
		</item>
	</channel>
</rss>

