Domain Redirection with HTAccess

The Scene

If you are playing with domain hack as I am, one thing to think about is to redirect the visitors reaching the primary domain to the sub-domain. For instance, I want to make sure whoever visits "http://icio.us" gets redirected to "http://del.icio.us" properly.

How do we do that? The answer varies depending on the method we take. I’m introducing a way which takes advantage of the mod_rewrite feature of apache servers.

The Solution

The relative paths look something like this:

/ <- http://icio.us

/del/ <- http://del.icio.us

Establish a .htaccess file in the root directory with content below:

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^(.*) http://del.icio.us/$1 [R,L]
</IfModule>

This way each request to "http://icio.us" will be redirected to "http://del.icio.us". Follow the htaccess tutorial and modify RewriteRule to create more complicated redirection rules as you wish.

Technorati Tags: ,

作者:Keefe Dunn

a dreamer, a learner, a lawful beginner.

1条评论

发表评论

您的电子邮箱地址不会被公开。