Forum Moderators: phranque

Message Too Old, No Replies

Redirecting ~username to domainname?

A typical newbie question

         

Arachne

6:58 am on Aug 8, 2005 (gmt 0)

10+ Year Member



Please forgive the eternal question of all Apache newbies - although I'm sure this has been asked more than once, I unfortunately couldn't find an answer anywhere.

I run a site at [domainname.net...]

Google ALSO indexes the site at its local path address, namely: [host.org...]

I'd like to use mod_rewrite to have all incoming host.org requests rewritten to domainname.net. I cobbled something together from an example in a previous WW post, here [webmasterworld.com]. It HALF-works:

RewriteCond %{HTTP_HOST} ^domainname\.net [OR]
RewriteCond %{HTTP_HOST} ^(www\.)?host\.org/~username
rewriterule (.*) [domainname.net...] [R=301,L]

The first half of this works fine - domainname.net gets sent to www.domainname.net, and there was much rejoicing.

However the second half does not work - www.host.org/~username does not get sent to www.domainname.net, nor does host.org/~username.

How can I get this regex right? As far as I can tell, the second RewriteCond SHOULD work. Am I doing something obvious wrong?

Thank you for your time! It's much appreciated.

ChadSEO

3:36 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Arachne,

Welcome to WebmasterWorld!

You are trying to match HTTP_HOST, which contains only the host, to the whole path. Also, am I right in concluding you are wanting to redirect to just http://www.example.com? If so, this should work a little better for you:

RewriteCond %{HTTP_HOST} ^example\.com [OR]
RewriteCond %{REQUEST_URI} ^/~username
RewriteRule .* http://www.example.com/ [R=301,L]

Arachne

7:56 pm on Aug 8, 2005 (gmt 0)

10+ Year Member



Thanks, ChadSEO, that worked like a charm! Fabulous magic and much appreciated. :)