Forum Moderators: phranque

Message Too Old, No Replies

mod rewrite - www, non-www both to a new domain

redirect example.com and www.example.com to new.com

         

rjljr

7:53 pm on Jun 15, 2009 (gmt 0)

10+ Year Member



Hi-

This is my first post. I found this forum via google. I have been fussing with this off and on for a couple weeks. I can get it to work for one, but not both.

I have a site - example.com.

both example.com and www.example.com take you to the same page. my company (example) was acquired, and i need the browser address bar to now show the new company name - new.com

i have successfully redirected other parts of the site - support.example.com to new.com/support, for example, using this code:


RewriteEngine On
RewriteCond %{HTTP_HOST} ^support.example.com
rewriterule (.*) http://new.com/support/$1 [R=301,L]

i have tried this with example.com to new.com, and it works. but i lose the www.example.com to new.com.

I have tried using a rewriteCond with the www, with no luck.


RewriteEngine On
RewriteCond %{HTTP_HOST} ^www.example.com [nc]
RewriteRule (.*) new.com/$1 [R=301,L]

I have also tried using the www.example.com line with an OR:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^example.com OR
RewriteCond %{HTTP_HOST} ^www.example.com [nc]
rewriterule (.*) http://new.com/$1 [R=301,L]

also with no success.

To complicate things - example.com was hosted internally, and IT set up something on the IIS server which handles the www to non-www mapping for example.com and www.example.com to make them go to the same page.

The new site is also hosted on a windows server, which is running ISAPI_Rewrite 3.

I feel like this should be possible - but I have not found the right combination yet.

So my question is - is this possible to rewrite new.com when someone enters www.example.com or example.com?

Thanks very much - all help appreciated.

[edited by: jdMorgan at 1:09 am (utc) on June 16, 2009]
[edit reason] de-linked [/edit]

jdMorgan

12:43 am on Jun 16, 2009 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Bad syntax. Try:

RewriteEngine on
RewriteCond %{HTTP_HOST} ^example\.com [NC,OR]
RewriteCond %{HTTP_HOST} ^www\.example\.com [NC]
RewriteRule (.*) http://new.com/$1 [R=301,L]

or the more compact

RewriteEngine on
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com [NC]
RewriteRule (.*) http://new.com/$1 [R=301,L]

This code is for use on Apache servers, and may or may not be compatible with ISAPI Rewrite on MS servers. No warranty is expressed or implied...

Jim

[edited by: jdMorgan at 1:08 am (utc) on June 16, 2009]

rjljr

1:06 am on Jun 16, 2009 (gmt 0)

10+ Year Member



Jim -

Thanks very much. I tried the compact version - and it works perfectly - while running ISAPI Rewrite 3.

Thanks very much!
Bob