Using htaccess to create a subdomain on apache

Using htaccess to create a subdomain on apache

Posted by Diezel on Wed, 2008-02-20 21:25

I've been thinking of starting a blog to keep my thoughts and ideas together in one place. To do this I wanted to use a simple subdomain to nixadmins.net like blog.nixadmins.net. To do this in a simple way without touching too much of the configuration I did it using the Apache's .htaccess file.

The htaccess file can be used to many things, in this short short story I'll only go in to creating a working subdomain. But you can find a lot more in the htaccess tutorial.

If you have a .htaccess file you can modify it, if not just create a new one in any editor.
Put the following lines in it, and of course change the values to suite your need.

<IfModule mod_rewrite.c>
RewriteEngine on
# Rewrite for Wordpress blog
RewriteCond %{HTTP_HOST} blog.nixadmins.net
RewriteCond %{REQUEST_URI} !blog/
RewriteRule ^(.*)$ blog/$1 [L]
</IfModule>

After that, create a DNS cname record, of blog.nixadmins.net that points to the same server, for me www.nixadmins.net. And you are done.

Post new comment
The content of this field is kept private and will not be shown publicly.