4

My problem seems simple to me but I cannot find a simple solution. Here goes: I have one main domain, and multiple domains pointing to that main domain. To avoid duplicate content I'm trying to redirect all "secondary" or "parked" domains to my main domain so that it resolves to this:

  • www.parkeddomain1.com => www.maindomain.com
  • www.parkeddomain2.com => www.maindomain.com
  • www.parkeddomain3.com => www.maindomain.com

And so on...

Now I have found this htaccess code that is sort of a catch-all solution (which I would prefer):

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.maindomain.com$
RewriteRule ^(.*)$ http://www.maindomain.com/$1 [R=301]

So this code works when I'm dealing only with straightforward parked domains, not with parked domains with subfolders or subfiles. So:

  • www.parkeddomain1.com => www.maindomain.com

redirect works fine here but when I add a subfolder this happens:

  • www.parkeddomain1.com/subfolder/ => www.parkeddomain1.com/subfolder/

when what I'm looking for is:

  • www.parkeddomain1.com/subfolder/ => www.maindomain.com/subfolder/

All this in order to avoid the duplicate content problem with search engines.

Thanks to all for any answer that would guide me to a solution.

Cheers!

3 Answers3

3

If the questioner starts rewrite ruling with [R=301] 301 redirect, a.k.a. “Permanently Redirect”, and then he try to view his URL www.parkeddomain1.com/subfolder/ but the result of the rule wasn't what he want, then even he try to change the redirecting rule, his web browser will always redirect that URL into the first URL where it redirecting with [R=301] flag. Because once the browser has been redirected permanently to the wrong address, even how many times you edit the rule, your browser will still be redirected to the old address, that's a browser thing, and you may even go on to fix the rule, and then change the rule all over again without ever knowing it. Changes the 301 redirects in your browser can take a long time to show up.

The solution is to restart the web browser, or use a different one. So, if you're testing, it's better to use a [R] flag instead of [R=301] flag. And when you are 100% sure that the rule does exactly as it's expected to, then switch it to [R=301] flag. Or else, this question belongs to Server Fault.

Community
  • 1
  • 1
2

If your sole aim is to appease search engines, you can alternatively specify a canonical URL which tells search engines the definitive URL for a piece of content. So even if the same content is served by several different query-string variants, or several different domains, the canonical URL will tell the search engine that these are just alternatives to the one true URL.

See the Google Webmaster Central Blog about Canonical URLs for the details.

Bobulous
  • 12,967
  • 4
  • 37
  • 68
1

Try adding the "L" after 301

RewriteEngine on
RewriteCond %{HTTP_HOST} !^www.maindomain.com$
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]
Edson Medina
  • 9,862
  • 3
  • 40
  • 51