Forum Moderators: phranque

Message Too Old, No Replies

Having multiple domains pointing to a single site

         

tom12c

7:20 pm on May 19, 2010 (gmt 0)

10+ Year Member



Hey Guys, I'm in the process of trying to seeing what I can to redirect traffic going to duplicate sites from google to my real site.

Not sure how this happened, but depending on what you type in google, duplicate domains are now being displayed as links for search results. I'd like for google (and other search engines) to completely forget about these duplicate domains happy!

I read [on another site] about an IP funnel but I'm not entirely sure we use that.

And [on yet another site], I read to use a 301 redirect like this:

RewriteEngine On

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]

Which don't get me wrong, does work, but unfortunately, I recently discovered there are approximately 100 domains I would need to take care of.

I rather not write have a .htaccess file looking like this...

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite2.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite3.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite4.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]
RewriteCond %{HTTP_HOST} ^(www\.?)yourduplicatesite5.com$
RewriteRule ^(.*)$ http:www.example.com/$1 [R=301,L]

etc

Might there be an easier/cleaner way to do it?

Would appreciate assistance. Thanks!

Tom

[edited by: jdMorgan at 8:47 pm (utc) on May 19, 2010]
[edit reason] example.com & de-linked [/edit]

jdMorgan

8:40 pm on May 19, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member




RewriteEngine On
#
# Externally redirect all requests for non-blank non-canonical hostnames
# to the canonical hostname, preserving the requested URL-path
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

Or, if your site supports SSL and both SSL and non-SSL requests resolve to the same virtual host:

RewriteEngine On
#
# Externally redirect all requests for non-blank non-canonical hostnames to the
# canonical hostname, preserving the requested http/https protocol and URL-path
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteCond %{SERVER_PORT}s ^(443(s)|[0-9]+s)$
RewriteRule ^(.*)$ http%2://www.example.com/$1 [R=301,L]

Replace "www.example.com" with your own canonical (preferred) hostname, escaping the literal periods exactly as shown.

This code is intended for use in the top-level .htaccess file or within a <Directory /> container in a server config file such as httpd.conf or conf.d. For use in a config file outside of any <Directory> container, add a leading slash to the RewriteRule pattern, making it "^/(.*)$"

P.S. Computers actually run on comments. That's why un-commented code often works so poorly. :)

Jim

tom12c

9:40 pm on May 19, 2010 (gmt 0)

10+ Year Member



Thank you for your quick reply!

I'm reading your post but I'm unsure exactly what you are doing.

RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$

What does the "\" do?

Please let me know. Thanks!

Jane_Doe

1:44 am on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Some of the registrars have "check box" domain forwarding as an option. I used these options recently instead of making my own individual .htaccess files and it worked great. I forwarded two old domains to a third new domain for a nonprofit that for various reasons had three domains floating around from past years, with various links to all three domains. Now all of the domains resolve to the current site, the most recent and current domain comes up first in all of the search engines and the back links all point to the current domain.

Terabytes

2:03 am on May 20, 2010 (gmt 0)

10+ Year Member



I'm not saying that the "check box" solution is wrong or bad or anything like that. However I'm not sure I'd trust my host (or any host) to handle redirects properly for any domain I own. I'd have to do it myself and know it's done correctly.

Just my $0.02
Tera

jdMorgan

3:18 am on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



"^(www\.example\.com)?$" is a regular expressions [etext.lib.virginia.edu] pattern, which is negated by the preceding "!"

Literal periods within regular-expressions patterns (and a few other characters as well) must be escaped by preceding them with a "\". Otherwise, the period is taken as a regex token meaning "match any single character."

"^(www\.example\.com)?$" matches *exactly* the string "www.example.com" or an entirely-blank string. Therefore, with the preceding negation operator, any requested hostname which is not blank and is not exactly-right will be redirected.

The provision for a blank hostname is to avoid an infinite redirection loop should an HTTP client fail to send an HTTP Host header with its requests. Wise webmasters do not depend on the kindness of others for the proper operation of their servers... and there's a nice tie-in with Tera's post, too.

Jim

phranque

7:36 am on May 20, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



what Terabytes said!
i've seen several technically incorrect implementations of domain forwarding by registrars.
for example, 302 Found status code responses.
best to take the original request at your host and do the right thing (301).

Jane_Doe

11:21 pm on May 20, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



I'd have to do it myself and know it's done correctly.


I didn't know if this would work either at first, but heh, there is only one way to find out. Worst case it wouldn't have worked and I would have had to write my own 301 redirects.

You have to do what works best for you, but to me time is money. This worked out fine and it took all of 60 seconds including login time. Rankings improved, the backlinks now all point to the current site and everything resolves correctly so I'm not seeing any downside here.

It is a small, very low traffic site for a nonprofit I don't get paid to work on so its not like anybody would have been out a million dollars if the rankings went to page two for a week until I fixed the .htaccess code. (If I had needed to do that, which I didn't.)

jdMorgan

1:49 am on May 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> I'm not seeing any downside here.

If your control panel is like most, and your canonical domain is "www.example.com", try the following URLs for your "home page"

example.com/ (probably works, redirects to www.example.com)
example.com./ (valid FQDN, but non-canonical)
www.example.com./ (valid FQDN, but non-canonical)

Others that likely won't work (that is, they may not get redirected), but can only be tested with Telnet or similar tools:

example.com:80/
example.com.:80/
www.example.com:80/
www.example.com.:80/

If your control panel manages to cover of all these duplicate-content cases, then it's better that 99% of all control panels out there...

Now, if your home page resolves to a file, say "/index.php", try these:
example.com/index.php
example.com./index.php
example.com:80/index.php
example.com.:80/index.php
www.example.com/index.php
www.example.com./index.php
www.example.com:80/index.php
www.example.com.:80/index.php

The control panels that I know of don't redirect to fix this problem either.

And if we add a query string to these URLs and they don't get redirected to remove it and don't return 404-Not Found either, then the URL-space for your home page pretty much becomes infinite.

However, as long as no-one links to these non-canonical URLs, you should be alright. If you don't have any competition, or if they are all kind and good, or they don't know about linking tricks, no worries.

Jim

Jane_Doe

3:43 am on May 21, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If your control panel is like most, and your canonical domain is "www.example.com", try the following URLs for your "home page"


They work for example1.com and www.example1.com, www.example.com/, pretty much everything in your first set.

Others that likely won't work (that is, they may not get redirected), but can only be tested with Telnet or similar tools


I don't know Telnet and I don't know any linking tricks so I don't have any idea what the 80/ is for or what specific problem it would prevent.

phranque

9:17 am on May 24, 2010 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



to avoid canonicalization problems you should redirect any requests that include default elements in the url.
80 is the default port for HTTP protocol, which may be specified in the home page url as:
http://example.com:80/
which should be 301 redirected to http://example.com/

similarly if the default directory index document is index.php you want to 301 redirect requests for http://example.com/index.php to http://example.com/

and the same goes for default or junk/ignored parameters, etc.

tom12c

1:00 pm on Jun 8, 2010 (gmt 0)

10+ Year Member



jdMorgan: I just wanted to give a massive thank you. It appears to be working flawlessly.

For the others talking about the checkbox option, that wasn't quite an option unfortunately. But thanks for taking the time to discuss it.