ID #396

How can I use mod-rewrite to make requests for one domain go to a subdomain of another domain?

Applies to: Grid System

In this scenario, you want requests for old-domain.com to go to a subdomain of a new domain, such as sub.new-domain.com. To do this, follow these steps:


  1. Create the relevant subdomain, sub.new-domain.com, under your main domain (new-domain.com) that you host at Modwest. For instructions on creating a subdomain, go here.
  2. Add old-domain.com as a Domain Alias to new-domain.com: For instructions on creating a Domain Alias, go here.
  3. Use Apache's Mod_Rewrite to make requests for old-domain.com actually requests for sub.new-domain.com. If you haven't used mod_rewrite before, then you can follow these instructions:
    Create and upload the file /htdocs/www/.htaccess with the following mod_rewrite code:
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} old-domain.com$ [NC]
    RewriteRule ^(.*)$ http://sub.new-domain.com/$1 [R=301]

    NOTE:The [R = 301] stands for 'permanent redirect', which will tell Google bots that old-domain.com and sub.new-domain.com are the same site. This may be important to you for Search Engine Optimization.

    Learn more about Apache's mod_rewrite here: httpd.apache.org/docs/2.0/mod/mod_rewrite.html

Last update: 2010-10-05 16:21
Author: FAQ Admin
Revision: 1.2

Digg it! Share on Facebook Print this record Send FAQ to a friend Show this as PDF file
Please rate this FAQ:

Average rating: 5 (1 Vote)

completely useless 1 2 3 4 5 most valuable

You can comment this FAQ