Forum Moderators: phranque
I didn't think much about this until I got a Google Alert today that G had indexed one of my html pages, using the .com domain, and when I clicked on the link, sure enuf, I ended up at www.example.com/somepage.html. This in itself is not a bad thing, but it isn't what I want happening (no pagerank or advertising for the .com). I want any GET request for www.example.com/requested_page.html to redirect to www.example.net/requested_page.html.
I have tried doing that using the following rule, but the best I can get is a redirect to my .net homepage, not the requested uri...
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule .* http://www.example.net/$1 [R=301,L]
All of my other normal rewrite rules and redirects work ok. I only have this problem with parked domains. However, I am able to successfully rewrite a request for a particular parked domain root request (/) to one particular html page or directory/, but I can't specify a url on the parked domain and end up at the equivilant on my master .net (sigh).
Is this do-able or am I trying to do something that is beyond what is available when using a shared hosting account? (I can do anything I want with my own account, with my own .htaccess, but have no access to the server config files.
Tia, Wiz
Thanks for posting what you have tried... It is very much appreciated. What you would like should be possible with couple of small adjustments to your ruleset. You appear to be very close in what you have:
RewriteCond %{HTTP_HOST} ^www\.example\.com
RewriteRule .* http://www.example.net/$1 [R=301,L]
The adjustments:
RewriteCond %{HTTP_HOST} ^(www\.)?example\.com
RewriteRule (.*) http://www.example.net/$1 [R=301,L]
Condition: Make the www. optional, so we redirect www.example.com and example.com
() = Create a grouping (also a variable, but we won't use that part)
? = 0 or 1 of the preceding groups or characters
Rule: Create a variable to pass to the right side of the rule
() = Create a variable
Without the () on the rule, you would match all requests, but would not redirect to any page except example.net/ because there was no information stored.
By making the www. optional on the condition, we saved the need for a separate rule/condition for non-www requests.
As I said before you were very close =)
Hope this helps.
Justin
As regards the optional www expression, I don't want to do that at all. The rule just before this one makes sure that ALL requests for example.com are redirected to www.example.com, to avoid penalties with certain search engines ;-)
Here is that rule, in case anybody else needs to use it:
RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} ^example\.(com¦net¦info)
RewriteRule (.*) http://www.example.net/$1 [R=301,L]
Wiz