Redirecting a subdirectory to a subdomain

You know, the older versions of CPanel are weirdly quirky. One of those things that annoyed me was that all subdomains are also subdirectories. For example, if you create the subdomain george.arjie.com, then all files for that subdomain are stored in the folder accessible at arjie.com/george. This is very annoying if you have want web spiders to index your content because they’ll sometimes completely ignore the subdomain and index everything at the subdirectory. This was a rather painful issue for me because http://blog.arjie.com was rather well indexed but http://blog.arjie.com/, the actual address, was nearly completely untouched by Google — there was one result, the subdomain root.

In any case, I decided to make everything point to blog.arjie.com now and spent the better part of the last hour trying to get the right commands in my .htaccess file. The thing with .htaccess is that if you make a mistake you don’t get told what it is, you get a 500: Internal Server Error message, which is about as helpful as a monkey with a tyre iron but not. So I’ve got it all figured out finally so here’s the relevant bit of the .htaccess that I’ve placed in my blog.arjie.com subdirectory:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?arjie\.com$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://blog.arjie.com/$1 [R=301,NC,L]

and since I searched for a similar solution and didn’t find anything like it on the Internet. Here’s a version that I may be able to find by a Search Engine.
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ http://subdomain.domain.com/$1 [R=301,NC,L]

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>