Forum Moderators: phranque

Message Too Old, No Replies

301-redirect . multiple pages . 2 domains

301 redirect for multiple pages with 2 separate domain names

         

webservices4

4:20 am on Aug 1, 2007 (gmt 0)

10+ Year Member



Hello ...

I have a client that is getting penalized by Google for having duplicate content on singular & plural domain names (both sites have 800+ duplicate pages)

example.com has 175 pages indexed by Google
examples.com has 51 pages indexed by Google

If we're branding the singular domain (example.com), would a general 301-redirect from examples.com to example.com work, or will I need to set up separate redirects in the .htaccess file for the 51 pages for examples.com that are indexed?

Thanks in advance ;-)

jdMorgan

4:58 am on Aug 1, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



> would a general 301-redirect from examples.com to example.com work

Yes, use a general redirect of *all* examples.com URLs to their equivalent on example.com

[added] And also consider the same problem with URLs on both www.example.com and example.com... [/added]

Jim

[edited by: jdMorgan at 4:59 am (utc) on Aug. 1, 2007]

webservices4

7:24 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



Hi Jim,

Thanks for the above response. So, ideally, when I set up the 301-redirect on the plural (examples.com) domain, the current pages that are indexed in Google / Yahoo / MSN, etc. will eventually revert to the singular (example.com) domain for those URL's, right? Then, I wouldn't have to set up a 301-redirect for all of the pages on examples.com in the .htaccess file ... just a general one for that domain which will cover all URLs/files on that domain, right?

For domains hosting at GoDaddy, they now have a 301-redirect option. Is this ok to use, or would you advise a domain being hosted and the 301-redirect code applied to the servers .htaccess file?

Thanks again in advance.

g1smd

7:31 pm on Aug 1, 2007 (gmt 0)

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



You need a site-wide 301 redirect for all of these conditions:

examples.com --> example.com
www.examples.com --> example.com
www.example.com --> example.com

This ensures that only example.com can be indexed.

Point all of the domains at the one hosting plan and put all the redirect rules in the single .htaccess file on that server.

The redirect code is just two lines long for each site-wide condition.

webservices4

7:42 pm on Aug 1, 2007 (gmt 0)

10+ Year Member



Ok, so then on the "example.com" .htaccess file, this code would apply:

Options +FollowSymLinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]

Then, on the "examples.com" .htaccessfile, this code would apply:

redirectMatch 301 ^(.*)$ http://www.example.com
redirectMatch permanent ^(.*)$ http://www.example.com

... right?

The reason why I want to make sure I'm on the same page with this is because if there's already 51 pages indexed on the name we need to set the 301-redirect on, if I do the below code on that .htacess file, would that screw up the 51 pages already indexed, or do need to do each page in the .htaccess file for a 301-redirect.

... sorry for the confusion and thanks for your help

g1smd

12:11 am on Aug 2, 2007 (gmt 0)

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



Point all of the domains at the same hosting. You then need all of this in the single .htaccess file.

Options +FollowSymLinks
RewriteEngine on

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

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

Only pages from www.example.com will be indexed. The 51 pages indexed under the "wrong" domain will soon be reindexed under the correct domain.

They will then also pass internal PageRank to the correct pages on the correct domain too.

webservices4

12:35 am on Aug 2, 2007 (gmt 0)

10+ Year Member



Ok - thanks ...

When you say "point" all domains to the same hosting w/ only 1 .htaccess file, I'm still a little confused.

For example, when I pick up a domain name w/ a PR-4 from SnapNames, I usually set up separate hosting for that domain and put the 2 lines of code in the .htaccess file for the 301-redirect for that domain, to redirect to the "brandable" domain.

If all domains are suppose to be done on 1 .htaccess file on the brandable domain server, how is the pointing done? A general forward and then the .htaccess file recognizes the domain?

jdMorgan

5:14 pm on Aug 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can do it either way, as long as your host permits you to point many domains at your one "brandable" server. You'd just use that %{HTTP_HOST} server variable to decide what to do with requests for each domain.

You can use the "point all to one" approach if you're on a dedicated or VPS server, but this would generally not be allowed/supported on name-based virtual hosting.

Jim

webservices4

6:40 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Jim ... thanks, I really appreciate it.

I have a 20GB whm/cpanel server from RackForce so setting up multiple hosting accounts isn't difficult, just little extra work.

I just can't comprehend (wrap my brain) around the concept on one .htaccess file on the brandable domain server.

For example, let's say I have a domain at 1and1.com ... if I set a basic domain forward to the brandable domain, are you saying I can put the 301-redirect code on that brandable domain's .htaccess file to recognize that incoming domain is a permanent redirect?

Also - GoDaddy has 301-redirect selection in their backoffice ... in you opinion is this ok/safe/legit, or should the domain be configured for the 301-redirect with regular hosting (using the .htacess file).

Thanks.

jdMorgan

7:02 pm on Aug 2, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Forget forwarding, parking, and all that mickey-mouse stuff...

Clients (e.g. browsers) ask DNS about a domain name found in a requested URL.
DNS returns an IP address for that domain name.
Clients send the request to that IP address. They also send along the hostname in an HTTP header.
The server config (e.g. httpd.conf) points hostname requests to filesystem directories.
Apache gets the "page" from the filesystem and sends it back to the client.

That's the basis of all of this InterWeb stuff.

Note that things probably don't work exactly the way most people think they do. That's because, prior to HTTP/1.1 only one domain could hosted on an IP address. In response to the threat of running out of IP addresses, hostnames were added, and name-based virtual hosting, where multiple sites share an IP address, became possible. As such, hostnames were just sort of 'bolted on' to the HTTP protocol as an afterthought.

So domain names and hostnames are not quite the same thing, but for the purposes of this post, you can call them equivalent.

cPanel makes some very basic things very easy, but it's a canned, inflexible solution. Mostly it just gets in the way, but it can be used to corrupt your configuration if you wish... :)

If the DNS points all of your domains to your server's IP address, and all hostname requests are configured on the server to go to the same file space, then you could use one .htaccess file to do all the redirects.

Given that you have a better hosting plan level than most participants here, I'd say you might as well just add the extra domains into you account as "separate" hosts, and then redirect from there. The only advantage of the .htaccess approach might be centralized management. But if you're not a coder by nature, then the cPanel approach might be easier for you, and it will be faster performance-wise.

Just to de-mystify, cPanel is a program that can put pre-coded routines into the server configurations files, e.g. httpd.conf, conf.d, and .htaccess. It can change a few variables in those pre-coded routines, but is otherwise not very flexible. It also doesn't "write" very efficient code -- To be accurate, it tends to create very inefficient and ugly code, sometimes with notable flaws in it. It is simply an attempt to allow folks with limited server configuration skills to make a few customizations without blowing up the server and taking down their sites and other sites sharing the same server. In that light, it's an OK app.

Jim

webservices4

7:30 pm on Aug 2, 2007 (gmt 0)

10+ Year Member



Ok ... very good ... thanks, Jim.

That's basically what I do. When I get a good PageRank domain that I can use for a site, I'll set up hosting for that domain, but instead of playing w/ cpanel, I just use a .txt file and create a .htaccess file ... put in the 2 lines of code to 301-redirect this domain to the domain I want it redirected to, and it's all good.

So, then, for the whole point of my initial post, I'll set up separate hosting for examples.com and code this .htaccess file w/ the right 301-redirect code to redirect to example.com

Thanks for everyone's help ... I appreciate it.

webservices4

10:56 pm on Aug 16, 2007 (gmt 0)

10+ Year Member



Ok, so on the domain that was causing the duplicate content, I set up the 301 redirect on it to redirect to the name we are branding, but when you go to any of the pages indexed in Google, it will take me to the index page on the branded domain instead of the exact page

... is this ok?

jdMorgan

11:26 pm on Aug 16, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I certainly wouldn't recommend it. Can you post the code?

Jim

g1smd

11:55 pm on Aug 16, 2007 (gmt 0)

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



You need the (.*) and the $1 stuff in the redirect code so that the requested filepath is preserved in the redirect.

Make sure, too, that there is a [R=301,L] in there as well. There are a large number of example code fragments in other threads here.

webservices4

11:56 pm on Aug 16, 2007 (gmt 0)

10+ Year Member



The "plural" domain is causing the duplication so we're redirecting the "domainnames.com" to "domainname.com" ... here's the code in the .htaccess file for "domainnames.com" (plural):

redirectMatch 301 ^(.*)$ [domainname.com...]
redirectMatch permanent ^(.*)$ [domainname.com...]

webservices4

12:42 am on Aug 17, 2007 (gmt 0)

10+ Year Member



g1smd ... THANKS ... did some diggin' and some testing and here's my .htaccess code now for the plural domain:

redirectMatch 301 ^(.*)$ [domain.com...]
redirectMatch permanent ^(.*)$ [domain.com...]

RewriteEngine ON
RewriteRule ^(.*)$ [domain.com...] [R=301,L]


This is what you meant, right?

Thanks!

jdMorgan

2:04 am on Aug 17, 2007 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming that you are putting this code in .htaccess files, each of which is unique to one of the domain names, then any one of the following directives will work:

# mod_alias:
Redirect 301 / http://www.example.com/
Redirect Permanent / http://www.example.com/
RedirectPermanent / http://www.example.com/
RedirectMatch 301 (.*) http://www.example.com/$1
#
# mod_rewrite:
RewriteRule (.*) http://www.example.com/$1 [R=301,L]

They all do exactly the same thing in different ways: Each will permanently redirect all requested 'pages' in the current domain to the corresponding page in the stated domain.

If the code is going into a single .htaccess file that is common to all domains, then you must use mod_rewrite, and you must test the requested HTTP_HOST so that you do not redirect if the hostname is already the one you prefer. This code will redirect any request for a hostname other than the preferred (canonical) hostname:


RewriteCond %{HTTP_HOST} .
RewriteCond %{HTTP_HOST} !^www\.example\.com
RewriteRule (.*) http://www.example.com/$1

The first RewriteCond test to be sure the hostname is not blank, as it will be if an HTTP/1.0 request reaches this server. HTTP/1.0 does not support the "Host:" client request header that name-based-virtual servers depend on. If the Host header were blank and we didn't stop it, the code above would otherwise generate a redirect, and the HTTP/1.0 client would right come back with another request, again with a blank hostname. This would repeat in a loop, until the client reached its maximum redirection limit. However, if you are on a name-based virtual server, your site will be inaccessible to HTTP/1.0 clients, and you can therefore safely omit the first RewriteCond.

Jim