Forcing all requests from one domain name to go to another (and update address bar)

This is a mod_rewrite recipe that will force all requests for your hosting account to be
redirected to a particular domain.

Here’s an example:

You have

my-domain.com,
my-domain.net,
my-domain.org

on your account. You would like requests for any of the domain names to go to:

my-domain.com

and to update the address bar in the browser to reflect this.

Here’s how to do it :

Create a .htaccess file in your top web directory (the directory www for most users)

put the following lines in it:


RewriteEngine On

# this will force all domain requests to go to my-domain.com
RewriteCond %{HTTP_HOST} !^www.my-domain.com
rewriterule (.*) http://www.my-domain.com/$1 [R=permanent,L]

Leave a Reply

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