Forum Moderators: phranque

Message Too Old, No Replies

Which domain to redirect to? www or non www? rel=canonical? Htaccess?

         

fabulousyarn

1:21 am on Jul 21, 2010 (gmt 0)

10+ Year Member



Ok, here's my question:

To my dismay I have two versions of my domain indexed - one the www version, one the non-www version. There are two site maps - what did I know (ack). I am trying to fix everything now - a la matt cutts, and the htacess redirect to ONE domain, with ONE set of pages, no duplication. Right now the goog is correctly indexing the right amount of pages - 1100 of the non www one, and about 300 of the www one, and thats about all my content - but I'm trying to clean it all up, as I said. My question is - which do I redirect to. As far as I can tell, the www one has the better authority, more inbound links, older links, older references, stable page rank, etc. So I think I should do the htaccess with the redirect to get ALL things pointing to the www.domain.com version?

Below is the code recommended by GOOGLE ANALYTICS - I have a couple of questions -
1 - will this screw up analytics (which is set to track www.domain.com in the first place)

2 - will this pass on page 'juice' when the non-www versions are a lot of what is showing up in the index


3 - have I coded it write? Where the www is and the non www is? Or is this even what I need to do?

4 - someone suggested doing on page rel= canonical redirects as per matt cutts videoo

Redirecting Aliases in Apache

If you are using an Apache webserver, the configuration can be easily modified to redirect all traffic originating under one of the aliases to the primary site. One way to do this is to create two VirtualHost entries. The first will be the primary domain which will include your normal configuration; the second VirtualHost will be for all the aliases and will redirect to the primary:

#---primary virtualhost

Servername www.maindomain.com
Serveralias maindomain.com
...

#---second virtualhost

Servername maindomain.com
Serveralias maindomain.com
RewriteEngine on
RewriteRule ^(.*) [maindomain.com$1...] [R=301]


As you can tell, I'm a tad confused.

jdMorgan

7:17 am on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Your questions are primarily SEO-related, but as you've researched the relative merits of the two hostnames, I can say that your conclusion is correct -- redirect non-ww to www.

Your config needs a tweak:

#---primary virtualhost
Servername www.maindomain.com
# (deleted serveralias)
...
#
#---second virtualhost
Servername maindomain.com
# (deleted serveralias)
RewriteEngine on
RewriteRule ^/(.*) http://www.maindomain.com/$1 [R=301]
...


Or, alternately:

#--- Single virtualhost with serveralias
Servername www.maindomain.com
Serveralias maindomain.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.maindomain\.com)?$
RewriteRule ^/(.*) http://www.maindomain.com/$1 [R=301]
...

Forget the "rel=canonical" on-page stuff, and the "preferred domain" settings in Google Webmaster Tools: They're proprietary band-aids and/or not supported by all search engines, and a waste of bytes -- especially when you've got full config access on the server...

You could also use a simple

Redirect 301 / http://www.maindomain.com/

instead of the rewriterule directives in my first example. Mod_alias is a simpler module than mod_rewrite, takes only one line, and might be a bit faster.

Jim

fabulousyarn

5:02 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



OMG Jim, thank you - so simple - so I just upload a .htaccess file with the following in it? I'm nervous about doing this so bear with me :)_

#--- Single virtualhost with serveralias
Servername www.fabulousyarn.com
Serveralias fabulousyarn.com
RewriteEngine on
RewriteCond %{HTTP_HOST} !^(www\.fabulousyarn\.com)?$
RewriteRule ^/(.*) [fabulousyarn.com...] [R=301]


Thats it? That simple?

If i did the redirect 301 - how would I could that
is this the 'mod-alias that ou are refireeing to or am I missing something?

judy

fabulousyarn

5:12 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



sorry, I meant would i CODE that, and YOU ARE REFERRING...

.htaccess goes in the httpdocs folder, or above it?

tks

fabulousyarn

5:30 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



weeeellllll...that didn't work - uploaded the following to my httpdocs folder (main folder for the domain) and got a server error. I knew I'd do something wrong. Gack. Help. So then I relooked and saw that the last line had gotten screwd up with a URL duh - trying again!

fabulousyarn

5:38 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



ok, so, as far as I can tell I've duplicated your second one - and when I upload it I get a server error for the fabulousyarn.com domain. I'm trying your first example now..see if that works.

fabulousyarn

5:40 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



hmmm...simple redirect doesnt seem to do anything to either domain...hmmm

jdMorgan

6:07 pm on Jul 23, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I'm really not following along here...

If the mod_alias code (look up the Apache mod_alias documentation and see its directives' descriptions) does not work, then just the mod_rewrite code... It's possible that you haven't loaded mod_alias on your server, in which case none of its directives will work, and you'll get 500 Server errors if you try to use them.

And speaking of which, the first stop after a 500-Server Error is your Server Error Log, which will often tell you exactly what went wrong...

You're getting fairly deep into server configuration here -- the literal foundation of your site and its success or failure. Investing time in a bit of research at Apache.org would be very wise... :)

Jim

fabulousyarn

6:13 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



I am there and doing that. Have been but its been a coons age since I got this deep into it. Matt makes it seem so.....EAAAAZZZYYY...not.

I use .htaccess in a subdirectory of this server (a wordpress site) -

Basically, I tried all three variants - the first two basically just disabled one of the forms of the URL, the last diabled both of them.

I guess the only thing to me that is unclear is the exact coding of the last example you use - and I don't seem to find it anywhere - I am looking, believe me.

WHen you wrote: Redirect 301 / [maindomain.com...]
I am assuming that this is exactly what goes into the .htaccess file - that is why I asked what you were referring too... if I was missing some surrounding text or incorrectly assuming that this went into the.htaccess file or if it needed to go somewhere else.

Tks

fabulousyarn

6:37 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



Tks - both the mods are installed so I must be coding something wrong. Am trying to research it,b ut as far as I can tell I've duped your code character for character - I see the rewrite in apache information as well - but they are just not working....

fabulousyarn

6:55 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



Redirect 301 / [fabulousyarn.com...]

This doesnt work as well so I've opened a ticket with my host - this disables anyting below the main page - any url that doesnt have the www. in it, so that doesnt work. They are running apache 2.2.8 and say that both mods are enabled

fabulousyarn

6:55 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



sorry it converted it to a link didn't mean to do that, but you get the picture

g1smd

7:03 pm on Jul 23, 2010 (gmt 0)

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



The code in post 4175430 is intended to go into the httpd.conf file, not in the .htaccess file.

fabulousyarn

7:22 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



ah, well, that could explain it - but the first example, is that also meant for the config file? if so, yes, that would be a problem. However, the 301 redirect doesnt work either, so....tks,

fabulousyarn

7:23 pm on Jul 23, 2010 (gmt 0)

10+ Year Member



I guess also this is what makes it confusing - the code that I pasted, which you gave me the tweaks on, was clearly indicated in the webmaster tools info I saw to go in the htaccess file - but now I'm going to have to go back and double check...tks

jdMorgan

2:10 pm on Jul 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The URL-paths examined by the RewriteRule pattern in .htaccess or within <Directory> containers in server config files like httpd.conf are 'localized' -- That is, the path to the current .htaccess file's location is removed. So in httpd.conf outside a <Directory> container, you'd use:
 RewriteRule ^/entire/directory-path/page.html$ http://www.example.com/other-page.html [R=301,L] 


and in httpd.conf inside a <Directory> container of "<Directory /entire>" you would use
 RewriteRule ^/directory-path/page.html$ http://www.example.com/other-page.html [R=301,L] 


and in example.com/.htaccess, you'd use
 RewriteRule ^entire/directory-path/page.html$ http://www.example.com/other-page.html [R=301,L] 


while in example.com/entire/.htaccess, you'd use
 RewriteRule ^directory-path/page.html$ http://www.example.com/other-page.html [R=301,L] 


None of this applies to Redirect or RedirectMatch directives, because mod_alias is a different module, and works differently.

this disables anything below the main page - any url that doesn't have the www in it, so that doesn't work.

If you have some pages linking to "www" and others not, then you have a second (and big) problem that needs to be fixed. All links on your own site should refer to a single canonical hostname, and any request to your server that contains a non-canonical hostname should be immediately redirected to the canonical hostname.

Otherwise, you have a "duplicate content" problem -- The same content appearing at more than one URL -- and your site is essentially competing with itself for links and ranking. Because -in the eyes of search engines- there are two 'sites,' neither may rank as well as it should, and therefore, traffic to 'both sites' will be lower than it could be.

Jim

jdMorgan

2:25 pm on Jul 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



The main problem is that if you put either of the code snippets I posted anywhere except your config file, then all warranties are void -- They won't work.

Because you opened the thread with server config file code, that's where I assumed you wanted to put the new code. Most examples on the Web --and most here in this forum-- assume that the reader does not have config-file access to the server, and therefore, are coded for use in example.com/.htaccess.

The mod_alias code was intended to be used verbatim. If it's not clear look at the mod_alias documentation, and figure out what it says and how it works. The Redirect directive uses prefix-matching, and any part of the requested-and-matched URL that is not specified in the prefix gets copied to the end of the destination URL. Therefore, the example I posted affects *all* requests to the server.

You should put the domain canonicalization code in either a server config file or in the top-level .htaccess file of your site. Otherwise, you will have both serious/immediate and subtle/long-term problems.

The mod_alias version won't work in .htaccess because it is not "hostname-aware." It will therefore always redirect any request -- and create an infinite redirection loop.

Jim

fabulousyarn

4:17 pm on Jul 24, 2010 (gmt 0)

10+ Year Member



Hi Jim - this is what my hosting provider tells me needs to go into my .htaccess file in order to do the redirect.

# mod_rewrite in use
Options +FollowSymlinks
RewriteEngine On
RewriteCond %{http_host} ^fabulousyarn.com [NC]
RewriteRule ^(.*)$ [fabulousyarn.com...] [R=301,L]

Does this look right to you? I hesitate to just put this in because they say it will work...it looks right to me but..what do I really know!

Tks

fabulousyarn

4:21 pm on Jul 24, 2010 (gmt 0)

10+ Year Member



The above replaced the www.fabulousyarn.com with the URL, so please know that.


""If you have some pages linking to "www" and others not, then you have a second (and big) problem that needs to be fixed. All links on your own site should refer to a single canonical hostname, and any request to your server that contains a non-canonical hostname should be immediately redirected to the canonical hostname.

""Otherwise, you have a "duplicate content" problem -- The same content appearing at more than one URL -- and your site is essentially competing with itself for links and ranking. Because -in the eyes of search engines- there are two 'sites,' neither may rank as well as it should, and therefore, traffic to 'both sites' will be lower than it could be.""

Yes, I know - that is the impetus to fixing all this - and yes, I DID have lots of links internally pointing to the non-www domain - fixed now. Now I just want to make sure that any EXTERNAL links that are pointing to this (there aren't many are not pointing to this.

What is interesting is that google has NOT indexed pages twice - it has indexed some pages with the www, and some, without, but not indexed both, as far as I can tell.

Anyhow, that is why I am working so hard on fixing this - I hadn't realized that they were being indexed both ways - slip of the fingers when coding - very bad news.

Judy

jdMorgan

5:01 pm on Jul 24, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That code would work -- sort of. It's missing escapes on the literal periods, and won't help with FQDN-format hostnames or appended port numbers. I'd suggest:

# www.example.com/.htaccess
#
Options +FollowSymlinks
RewriteEngine on
#
# Externally redirect all requests for non-blank non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} !^(www\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

for use on sites which have only a single subdomain (i.e. "www"), and no plans to add more.

Further, unless you want to provide directory file listings for subdirectories containing no /index page, and unless your site uses content-negotiation (to support multiple languages, for example) I'd also suggest disabling those features by changing the Options directive above to

Options +FollowSymLinks -Indexes -MultiViews

Jim

g1smd

5:34 pm on Jul 24, 2010 (gmt 0)

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



Replace

RewriteCond %{http_host} ^fabulousyarn.com[NC]


with

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


and you're all set.

Ah. jd posted while I was away doing something else. Go with that answer.

fabulousyarn

11:02 pm on Jul 24, 2010 (gmt 0)

10+ Year Member



ok, thank you both. I really appreciate your help.

- for use on sites which have only a single subdomain (i.e. "www"), and no plans to add more.

Do you mean no subdomains like subdomainn.domain.com? I do have one.

Further, unless you want to provide directory file listings for subdirectories containing no /index page, and unless your site uses content-negotiation (to support multiple languages, for example) I'd also suggest disabling those features by changing the Options directive above to

I have only one directory containing pages, and it has an index.html file - I don't plan to have any other 'page' directories. Does that make sense?


Judy

jdMorgan

1:08 am on Jul 25, 2010 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



In that case, you may need to take that "other subdomain" into account:

# www.example.com/.htaccess
#
Options +FollowSymlinks -Indexes -MultiViews
RewriteEngine on
#
# Externally redirect all requests for non-blank non-canonical hostnames to canonical hostname
RewriteCond %{HTTP_HOST} !^((www|your-other-subdomain-name-here)\.example\.com)?$
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

If your other subdomain was added as a Control Panel "Add-on domain" this may not be necessary. One way to find out is to install the code with the originally-specified RewriteCond pattern (in my previous post), and then test your "other subdomain." If your request gets (mis-)redirected to the main domain, then you'll need to use this new RewriteCond pattern instead.

Jim

fabulousyarn

1:37 am on Jul 25, 2010 (gmt 0)

10+ Year Member



awesome tks

fabulousyarn

3:06 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Ok, one more question for you all - and again thank you so much for your help. If this were working - wouldnt it be that when you typed in [fabulousyarn.com...] in your URL/browser, it would redirect to [fabulousyarn.com?...]

Tks

fabulousyarn

3:07 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



that is, that it would be redirect from the url withOUT the www to the page with the www? Or do just the crawlers, indexers, pay attention to this?

fabulousyarn

3:27 pm on Jul 26, 2010 (gmt 0)

10+ Year Member



Hi - thanks - well, right now, the code they've given me works - when I test it with the seomoz crawl tool it shows that there is a permanent 301 redirect - which is what I'm supposed to do. When I added the mods you gave me, that didn't happen, so I've asked them to take a look. Right now, tho, I think i've got it at least working and am on the right road to realign all the content and the crawling and the URL's. Again, thank you.

judy