Forum Moderators: phranque

Message Too Old, No Replies

Forward any request at one domain to same page at another domain

         

moheybee

12:08 am on Jan 7, 2005 (gmt 0)

10+ Year Member



RewriteCond %{HTTP_HOST} ^(www\.)*domain1\.com
RewriteRule ^/$ [domain2.com...] [R]

www.domain1.com goes to www.domain2.com

domain1.com goes to www.domain2.com

but

www.domain1.com/contact/ stays at www.domain1.com/contact/

What am I missing?

jdMorgan

2:36 am on Jan 7, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> RewriteRule ^/$ http://www.domain2.com/$1 [R]

This rule specifically says that you only want to forward requests for "/" to the new domain, because you have end-anchored the RewriteRule pattern. It also says that this redirect is temporary, and that you want to process more RewriteRules after this one. And finally, you did not capture the requested "file", leaving back-reference $1 undefined, so all requests to domain1 (including those for images, css stylesheets, etc.) will be redirected to the home page of domain2.


RewriteRule ^/(.*) http://www.domain2.com/$1 [R=301,L]

will probably work better if your code is in httpd.conf, and you should use something like

RewriteRule (.*) http://www.domain2.com/$1 [R=301,L]

if you place the code in your Web root .htaccess file.

See our forum charter [webmasterworld.com] for some useful references on mod_rewrite and regular expressions.

Jim

moheybee

3:59 am on Jan 7, 2005 (gmt 0)

10+ Year Member



Thanks again Jim.

I'll check out that link too.