Forum Moderators: phranque

Message Too Old, No Replies

Problem redirecting requests for parked .com to .net domain

I can redirect to homepage, but not the requested html pages

         

Wizcrafts

4:54 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



I have a .net domain, that is well known and indexed. I took advantage of an opportunity to grab the expired equivilant .com domain and parked it, along with several other domain names, on my main server account. My account is on a CPanel shared host, running on Apache Server v1.3.33, Kernel Version 2.4.20-28.7smp. I share my IP address with numerous other people who have accounts on the same server.

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]

I have checked my hit-log for the desired page, after requesting that page on www.example.com, and it does show the HOST as www.example.com, so the HOST part is correct. It just refuses to forward to the requested page when it does the rewrite and I end up at www.example.net/ instead of www.example.net/requested_page.html.

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

jd01

10:16 pm on Jun 24, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi 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

Wizcrafts

11:33 pm on Jun 24, 2005 (gmt 0)

10+ Year Member



Thanks Justin, that worked! I needed to enclose the .* in parenthesis, as in (.*) on the left side of the expression, to get the redirect to work, just like you said. I just learned a fine point today. Thank you very much!

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]

This ruleset says that if the visitor, or search engine robot requests a non-www domain on my server, whether a .com, .net, or .info, it is redirected to my www.domain.net extension. This avoids a content duplication penalty with a S.E. beginning with a G.

Wiz