How-To: Redirect one domain to another with mod_rewrite
Apr.23, 2008 in
How To
Recently I needed to change the end of one of our domains from .com to .org. However we wanted to maintain any old links that pointed at the .com domain.
Using mod_rewrite you can achieve this move seamlessly for users, and keep all the parameters in tact. Simply add the following lines to your .htaccess file:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.example.com$
RewriteRule (.*) http://www.example.org/$1 [R=Permanent]
All requests for www.example.com will be rewritten to www.example.org. It’s that easy!
Tags: apache, mod_rewrite

April 30th, 2008 at 7:48 pm
Hello,
I have a more challenging problem. I have a subdomain like egypt.greatestdivesites.com and want to redirect it to http://www.greatestdivesites.com, but with maintaining the url of egypt so that I can use the php SERVER variables to find out at which subdomain I am but I will use the same code for each subdomain.
Can anyone help me.