Forum Moderators: phranque

Message Too Old, No Replies

The code for permenant redirect 301

I have two domains resolving in the same root directory

         

matrix_neo

12:19 pm on May 2, 2003 (gmt 0)

10+ Year Member



I have two domains resolving in the same root directory and I want to redirect one domain to the other. Can anybody paste exact code? and a bit of explanation? I am a webdesigner not a programmer I believe I can manage if not complex. Server info (Apache/1.3.27 (Unix) mod_log_bytes/0.3 mod_bwlimited/1.0 PHP/4.2.3)Thanks

jdMorgan

4:04 pm on May 2, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



matrix_neo,

Assuming you're on a shared-hosting setup, and have access to Apache mod_rewrite, you can use use this code in an .htaccess file in the web root directory of your account - the directory where your "home page" resides:


Options +FollowSymLinks
RewriteEngine on
RewriteCond {HTTP_HOST} ^(www\.)?domain2\.com [NC]
RewriteRule ^(.*)$ http://www.domain1.com/$1 [R=301,L]

That will redirect requests for files in www.domain2.com or domain2.com to the same files in www.domain1.com

Reference: Introduction to mod_rewrite [webmasterworld.com]

HTH,
Jim