<?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; subdomain</title>
	<atom:link href="http://nomulous.com/blog/tag/subdomain/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>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>

