Forum Moderators: phranque
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.
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]