Forum Moderators: phranque

Message Too Old, No Replies

Redirecting/Rewriting the host name

rather than the path

         

EBear

4:50 pm on Mar 24, 2004 (gmt 0)

10+ Year Member



Hi. There seems to be a wealth of experience here in Mod ReWrite and Mod Alias, so can anyone help me with the following problem?

I'm trying to tidy up a situation where widgets.example.com has been set up as a virtualhost in www.example.com. So widgets.example.com is the same as www.example.com/widgets.

To make matters worse, someone has gone and gathered a lot of links to www.widgets.example.com. I'd like to make all three versions appear the same to google and lead to the same URL.

So:

all requests to widgets.example.com remain unchanged (go to widgets.example.com);
all requests to www.example.com or www.widgets.example.com are rewritten to the same path at widgets.example.com;
all requests to bodgets.example.com are unaffected (go to bodgets.example.com - this for all virtuals other than widgets).

I tried using

Redirect permanent / [widgets.example.com...]

in the htaccess in the www root, but it got picked up by the /widgets folder, sending the server in a loop. All the examples I've found are based on rewriting paths rather than the host name.

Could I do something with a RewriteCond and HTTP_HOST?

I'm not familiar with these modules and I don't have a test environment to safely break, so any help would be appreciated.

jdMorgan

9:44 pm on Mar 24, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> Could I do something with a RewriteCond and HTTP_HOST?

Yes, precisely. For use in a .htaccess context:


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

Jim

EBear

10:49 am on Mar 25, 2004 (gmt 0)

10+ Year Member



Jim, you're a marvel, perticularly for the amount of time you seem to spend each day unselfishly helping newbies. Thanks a million.