Search code examples
apache.htaccessurl-rewritingsubdomainforum

How to redirect these kind of URLs which are formed upon creation of sub domain?


Here is my website by name iamfine.com and forum.iamfine.com is its sub domain.

Previously, the forum of iamfine.com was accessed by iamfine.com/forum, and now it is accessed by forum.iamfine.com.

I have not moved the file anywhere. I have just maintained them under the forum directory from the root directory.

I want to redirect all the forum URLs as below:

http://iamfine.com/forum/index.php

to

http://forum.iamfine.com/index.php

How can I do this?

I am using Red Hat Linux.


Solution

  • You need to rewrite the forum directory, but you need to check it isn't already in the subdomain.

    RewriteCond %{REQUEST_URI} ^(www\.)?iamfine\.com$
    RewriteRule ^forum/(.*)$ http://forum.iamfine.com/$1 [R=301,L]
    

    This is assuming your RewriteEngine is on, and that you want the 301 redirect.

    Apache Mod_Rewrite Documentation