Jump to content

  • Log in with Facebook Log in with Twitter Log In with Google      Sign In   
  • Create Account

Subscribe to HRA Now!

 



Are you a Google Analytics enthusiast?

Share and download Custom Google Analytics Reports, dashboards and advanced segments--for FREE! 

 



 

 www.CustomReportSharing.com 

From the folks who brought you High Rankings!



Photo
- - - - -

Permanent 301 Redirect


  • This topic is locked This topic is locked
320 replies to this topic

#1 exposure

exposure

    HR 3

  • Active Members
  • PipPipPip
  • 77 posts
  • Location:TX

Posted 20 April 2004 - 10:25 PM

Hi,

I'm sure this comes up often, but I couldn't find a recent request, so here goes...

Will one of you who knows how please post a layman's link or example with instructions on a permanent 301 redirect code? I'm going to get all non-www. versions of our homepages redirected to the www. versions. As a secondary question: is this a good idea? I keep reading it usually is. Thanks! :unsure:

#2 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 20 April 2004 - 11:02 PM

Hi and Welcome John !

There are a few ways to do what you're trying to get accomplished, so I'll touch a bit on each of them. FYI, these all apply to *nix server environments. So if your site is hosted on an IIS box completely disregard it all and let us know that.

First, and best IMO, is via BIND/Local DNS. If you have the ability to edit your local DNS records you could simply add a record to that to handle it seamlessly. If you don't have access to your local DNS you might ask your hosting company to set it up for you. Most will. Most do as a default these days. If you can edit the local DNS for the domain itself, simply add a CNAME record with the non-www version pointing to the www version.

Second, you could use mod_rewrite to accomplish the task. That would look like this:

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

Slap that into a file named .htaccess --after changing the yourdomain.com bit to your actual domain-- and you're set.

Or if your host doesn't support mod_rewrite you could also try various Apache Redirect commands in an .htaccess file. A simple 301 Redirect would look something like:

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

The above would take any request made to the domain it's installed on and send it off to "http://www.yourdomain.com/", appending any file name or directory structure to the URL string.

You could also try RedirctMatch for this type of "www" issue, though that's not what it's best used for. An example of this would be:

RedirectMatch 301 (.*) http://www.yourdomain.com$1

Both of the above will work, however I don't care for them much since they create a loop. In other words, regardless where someone is looking for the www or non-www address, they're going to get a 301 server header. It's a kludge, but sometimes this is all we have to work with.

You would think that RedirectMatch could be used to identify only the non-www accesses. That's not how it works however. The "Match" part of RedirectMatch is actually there to match regular expression patterns after the domain portion. So you can't perform a pattern match on ^/yourdomain.com.

However if you were, for example, converting your pages from using .html extensions to files of the same name but with a .php extension, RedirectMatch would be a good choice. That's what it's built to do. The example of this would look something like:

RedirectMatch 301 (.*)\.html$ http://www.yourdomain.com$1.php

Which of the above you use will depend a lot upon what your server supports. But if you're on a *nix server, one of the above should get you there.

[size=1]<Edited for correction of RedirectMatch examples. Sorry folks, I know better than to type that kind of stuff when I haven't reviewed the docs in months.>[/size}

Edited by Randy, 09 May 2004 - 09:19 AM.


#3 exposure

exposure

    HR 3

  • Active Members
  • PipPipPip
  • 77 posts
  • Location:TX

Posted 20 April 2004 - 11:17 PM

Hi Randy,

Many thanks for that thorough reply! I appreciate the time it took you. :unsure:

I have one additional question that just occurred to me: If I have established some incoming links at various sites using the non-www. version, will this have a negative impact on our sites in the SE's if we do the 301 redirect now? In other words, if I set up the permanent 301 redirect to the www. versions, will we still get the PR help from those sites linking to us with a non-www. link?

Thanks again!

#4 mcanerin

mcanerin

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,242 posts
  • Location:Calgary, Alberta, Canada

Posted 21 April 2004 - 01:07 AM

Welcome exposure (John)! :thumbup:

Thanks Randy, I've saved that to my fast reference file :eek:

Ian

#5 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 21 April 2004 - 07:21 AM

:lol: Ian! Perhaps I should save it too, hunh?

John: That's a bit of a ticklish question because the answer varies depending upon the search engine.

Google does a really good job with 301's, even passing PR eventually. It takes a little time for everything to get properly sorted, but at least it happens.

Inktomi (Yahoo!) on the other hand doesn't do a very good job where 301's are concerned. They've stated so publicly and that was still the case the last time I checked. However so much has changed recently with the INK/ATW/Altavista merging into Yahoo! Search that I've not tested to see if they're better with 301's now.

How about it everyone? Has anyone else taken at look at how Yahoo! is handling 301's these days?

I'd suggest trying to track down those links pointing to the non-www address and see if you can get the webmaster to change them. Takes time, but that's the sure way to make sure everything matches.

#6 exposure

exposure

    HR 3

  • Active Members
  • PipPipPip
  • 77 posts
  • Location:TX

Posted 21 April 2004 - 03:10 PM

Hi Ian, thanks for the welcome! :cheers:

Randy,

Once again, thanks for the informative response. Much appreciated! :thumbup:

#7 chrishirst

chrishirst

    A not so moderate moderator.

  • Moderator
  • 7,110 posts
  • Location:Blackpool UK

Posted 21 April 2004 - 04:22 PM

Just to cover most bases

a PHP 301

header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/newdir/newpage.htm");
exit();

and ASP 301

<%@ Language=VBScript %>
<%
Response.Status="301 Moved Permanently" 
Response.AddHeader "Location", "http://www.newdomain.com/newdir/newpage.asp"
response.end
%>

these scripts need to be at the top of the page before anything is sent to the browser

#8 robwatts

robwatts

    HR 5

  • Active Members
  • PipPipPipPipPip
  • 308 posts
  • Location:London - Hertfordshire

Posted 21 April 2004 - 04:48 PM

Some Q's come up time and time again.

This is a gr8 example of a thread that should be made sticky, great info guys!

#9 mcanerin

mcanerin

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,242 posts
  • Location:Calgary, Alberta, Canada

Posted 21 April 2004 - 06:59 PM

Agreed - pinned :)

Ian

#10 mcanerin

mcanerin

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,242 posts
  • Location:Calgary, Alberta, Canada

Posted 21 April 2004 - 07:19 PM

Since I'm apparently one of the few that uses MS Server I'll fill in the last blank. IIS handles this differently.

If you control the server, you open the Internet Services Manager, then choose the server running the site you want to forward.

Right click on the site and choose Properties > Home Directory

You will see the Following:
---------------------------------------------------
When connecting to this resource, the content should come from:
  • A directory located on this computer
  • A share located on another computer
  • A redirection to a URL
The default is the first one. Change it to "A redirection to a URL" and type in the new URL. Done.

There are more variables that can be passed on. You can see the official MS resource here: http://support.micro...;313074&sd=tech

If you don't control the IIS server, ask the admin to do the above.

Ian

#11 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 22 April 2004 - 08:38 AM

Cheers Chris and Ian!

These examples should pretty much cover the various flavors of hosting.

Excellent suggestion Rob!

#12 Ron Carnell

Ron Carnell

    HR 6

  • Moderator
  • 966 posts
  • Location:Michigan USA

Posted 22 April 2004 - 06:50 PM

If we're going to make this thread sticky and call it definitive, it might be useful to understand a bit of the why as well as the how. It might even lead to a slightly different solution? :lol:

First, it's probably important to realize that www.domain.com is technically the same thing as sub.domain.com, though it exists for a very different reason.

Ten or twelve years ago, the World Wide Web was just one small part of the Internet, and our fastest PC's were based on the brain-dead 386 chip. They weren't very fast and couldn't handle much of a load, so we often had to put the different parts of our Internet on separate machines. We'd put Apache on one computer, for example, and our mail server on another, and probably an FTP server on yet another. Each of the computers would respond to a different IP address, but still answer to the same domain name. We differentiated the computers with what we called, back then, a "machine name," and thus ended up with www.domain.com, mail.domain.com, and ftp.domain.com. (Anyone old enough to remember gopher.domain.com?)

Today's computers, of course, are much more powerful and we can put all of the different "parts" of our Internet services on the same box. Indeed, we often cram several hundred domains, each with its own set of parts, onto the same server. A few years ago, I argued (rather vehemently) that www was antiquated and should be ignored. Trouble is, a lot of big directories (Yahoo comes to mind) automatically list www.domain.com even if you submit a simpler domain.com, and we have a few billion people in the populace who habitually type www before any domain name. When I got tired of beating my head against that particular wall, I started recommending that everyone promote www.domain.com and get rid of domain.com. If ya can't beat 'em, join 'em.

The history, at least for me, is interesting, but the important thing to remember is that www.domain.com -- just like sub.domain.com -- is considered an entirely different entity than domain.com. A surfer or spider going to any of the three will receive the same 200 OK response code for a page request and won't readily be able to differentiate the domains.

The other important thing to realize, I think, is that in a more perfect world, we really don't want a Redirect sitting between domain.com and www.domain.com.

If someone yells "Ron!" across a crowded room, they're probably going to get my attention. If someone yells "Carnell" across the same room, I'm going to respond to that, too. That's because the two names, though entirely different, generally point to the same person. Over-simplifying a bit, we can say that Ron is essentially an Alias for Carnell.

If someone in that room walks up and addresses me as Randy, however, I'm probably going to look around, find Randy, and point him out as the one she's looking for (unless she's really cute, in which case I might lie.) Ron and Randy are two different names that point to two different people, so I need to Redirect the person's request to where it can be best answered.

On 99.9 percent of all server configurations, domain.com and www.domain.com point to exactly the same spot on the disk. One is just an alias for the other. Using a redirect makes about as much sense as someone calling me Ron, and me responding by pointing at my chest and saying, "No, you mean Carnell." Aliases and redirects don't mix very well.

Creating an alias is generally accomplished at two levels. At the DNS level, we always have to create an entry for each, usually a CNAME for each, or possibly a CNAME for the primary and an A entry for the secondary. If the domain in question is on a static IP address, this is all we need to do to create the alias.

Most of us, however, share an IP address with other domains, so we have to move beyond the DNS level to the web server level to complete the alias configuration. Using Apache as an example, an entry in the hpptd.conf (stripped down and simplified) might look something like this:

<VirtualHost 192.xxx.xxx.xxx>
ServerName domain.com
DocumentRoot /home/domain/www
ServerAlias www.domain.com
</VirtualHost>

That's all we need. Anyone, surfer or spider, going to either domain.com or www.domain.com will get exactly the same pages. Our problem, however, is that the URL doesn't change in the address bar and the page requests will result in 200 OK responses regardless of which domain is being accessed. Remember, www.domain.com and sub.domain.com look exactly the same to a search engine. The spider must, at least initially, treat both domain.com and www.domain.com as separate entities, even though we know they are aliases.

Google is the first search engine to incorporate sophisticated duplicate content filters and the logic necessary to eventually merge domain.com and www.domain.com into the same entity. Unfortunately, there's some small emphasis in that sentence on the word "eventually." If you use a DNS alias or a ServerAlias, Google will usually and eventually recognize the alias relationship and only show one in their SERPs. In most cases, when that happens there is ample evidence to suggest the PR from domain.com and www.domain.com will also be combined. Sadly, it usually takes several months to determine and, if you change your content frequently (meaning domain.com/page.htm and www.domain.com/page.htm, when spidered at different times might have different content), those several months can stretch out to a year or more. Who wants to wait? And when the guarantees are also pretty darn fragile, who wants to gamble?

It would seem none of the "big boys" want to either wait or gamble. Most of the PR 10 Sites we know about use only their www domain. If you try to access w3.org or adobe.com, you'll find your browser immediately redirected to the www version. It's not just an alias, because your location bar actually changes to the new www domain. We have to figure Google condones this, too, and not just because the big boys are doing it. Try going to google.com if you don't believe me. (Interestingly, most of the big boys use a Redirect 302. Only a handful, like w3.org, return a 301 status code. Presumably, Google treats them the same in this instance?)

So, instead of relying on aliases and duplicate content filters, which at best will only work with Google, someone came up with the brilliant idea of redirecting one alias to another alias, which is essentially a redirect to self. The bad news is this still only works well with Google, though even with other engines it will at least discourage people from linking to both domains and should thus avoid splitting your backlinks. The worse news, though, is that to create a redirect to self, we have to jump through a few technical hoops.

Did anyone wonder why, in Randy's first post above, he suggested both mod_rewrite and RedirectMatch, but didn't mention using a more simple Redirect? Why can't we eliminate all those complicated Regular Expressions and simply add a line like Redirect 301 / http://www.domain.com to our .htaccess?

We can't do it the simple way because we shouldn't be redirecting an alias and no one ever figured we would want to try. This is one of those things that is done ONLY because search engines exist. Since domain.com and www.domain.com are aliases and point to the same directory, any .htaccess directives in that directory have to apply to BOTH domains. A simple Redirect would just send our visitors in a vicious circle and eventually crash and burn.

Let's try a slightly different server configuration, one you are very unlike to ever see.

<VirtualHost 192.xxx.xxx.xxx>
ServerName domain.com
DocumentRoot /home/domain/www
</VirtualHost>

<VirtualHost 192.xxx.xxx.xxx>
ServerName www.domain.com
DocumentRoot /home/wwwdomain/www
</VirtualHost>

Notice in this configuration, domain.com and www.domain.com point to different folders on the server and therefore are NOT aliases. We can now put an .htaccess file in the /home/wwwdomain/www folder without affecting anything in the /home/domain/www folder and use the simpler Redirect command to meet our goals.

Problem solved. Except, unfortunately, we're wasting a bit of disk space and very few hosts would do this without charging for the extra resources. That's why you won't see this configuration very often.

It does, however, suggest another possibility.

<VirtualHost 192.xxx.xxx.xxx>
ServerName domain.com
DocumentRoot /home/domain/www
</VirtualHost>

<VirtualHost 192.xxx.xxx.xxx>
ServerName www.domain.com
Redirect 301 / http://domain.com/
</VirtualHost>

We're still configuring domain.com and www.domain.com as separate entities (not aliases), but instead of defining a DocumentRoot for one, we simply insert our simple Redirect statement. We avoid the contradictions of trying to redirect an alias by never creating one.

The disadvantage to this method is that it will require more work for the host admin. He has to define two blocks instead of one, but more importantly, he has to maintain both blocks in unison. If one is removed or altered, the other needs to also be removed or altered, and this introduces the very real probability of human error. (The real reason he will balk is because none of his utilities, like Cpanel or Ensim, will automate the procedure for him. At least, not yet.)

The trick is going to be to convince your web host that the advantages TO THEM outweigh the disadvantages.

Your .htaccess file introduces overhead to the server. Every single page request made to your domain will result in a read operation for .htaccess and a parsing of the file. That constant rereading and reparsing is why you can change your .htaccess and have the changes take immediate effect. Now throw in all those Regular Expressions that have to be evaluated for every single page request, and then multiply all of that by the 200 to 500 other domains sitting on the server. Your web host is going to find they can put fewer and fewer domains on a single box if all those domains are jumping through technical hoops in order to accomplish a simple redirect.

A redirect placed in httpd.conf, however, requires no fancy RegEx evaluations and more importantly is read and parsed exactly ONCE. Apache reads httpd.conf when it is first booted, memorizes it, then ignores it until the next reboot. The processing is minimal and the load on the server even less so.

Redirecting an alias is a contradiction, and one that exists only because of the search engines. Everyone, including the big boys, including even Google, does it, but it will always be just a kludge. We need the redirect. A more elegant solution, IMO, is to avoid creating the alias in the first place. That it makes our servers run more efficiently is a nice side-benefit. :)

#13 Randy

Randy

    Convert Me!

  • Moderator
  • 17,540 posts

Posted 22 April 2004 - 08:24 PM

:applause: Excellent lesson Ron.

I'm sure everyone, especially non-techies, will benefit from the historical explanation.

#14 mcanerin

mcanerin

    HR 7

  • Active Members
  • PipPipPipPipPipPipPip
  • 2,242 posts
  • Location:Calgary, Alberta, Canada

Posted 22 April 2004 - 10:20 PM

An interesting note: if you use the Yahoo Webrank tool:

http://www.digitalpo.../tools/webrank/

The www.domain.com and domain.com will very often give different numbers - usually the domain.com works and the www.domain. com does not. Since (for some reason) I can't install the Y! toolbar I can't be sure if this is the way DP programmed the script or if it's a Yahoo thing.

If it's a Yahoo thing, and not just a toolbar issue, then it would suggest that Yahoo is handling these issues in a different way from Google. Can anyone confirm this? It may affect how Y! calculates links.

Ian

#15 JamesW

JamesW

    One who makes no mistakes, never makes anything

  • Active Members
  • PipPipPipPipPip
  • 529 posts
  • Location:North-West England

Posted 21 May 2004 - 03:27 AM

I trust this redirecting business is completely white hat?

Also, can this equally be applied if you have a www.domain.com and www.domain.co.uk and want to point the .co.uk to .com?

Cheers

James




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users

SPAM FREE FORUM!
 
If you are just registering to spam,
don't bother. You will be wasting your
time as your spam will never see the
light of day!