Jump to content

Cre8asiteforums Internet Marketing
and Conversion Web Design


Photo

In-depth 301 Redirection Tutorial


  • Please log in to reply
23 replies to this topic

#1 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 03 November 2005 - 07:44 PM

Hi

I just completed a two-part in-depth tutorial about 301 redirection.

It explains the problems associated with incorrect redirection from the SEO point of view, explains the HTTP codes and why 301 is the correct one, and then goes on to give code examples of redirection using PHP and mod_rewrite.

I know there are a lot of such tutorials on the web, but this one goes into technical details that I haven't seen yet. It's aimed at the webmaster who wants to understand WHY and how this is done on a technical level.

Anyway, comments and questions welcome :)

#2 wiser3

wiser3

    Gravity Master Member

  • Members
  • 227 posts

Posted 08 November 2005 - 09:30 AM

Great tutorial, i learned a lot.

I checked my largest clients site by going to google and searching for both site:www.jokabsafetyna.com and site:jokabsafetyna.com to find that google has both indexed as seperate sites. Back to the tutorial to fix it.

I know my host supports .htaccess (i use it for other things) so i figured that would be the best method. I copy and pasted the mod rewirte code for "To forward mysite.com to www.mysite.com" and changed both occurances of mysite to jokabsafetyna.

I know it will take a while for googlebot to reindex the site and remove the double entry, but in going to both www.jokabsafetyna.com and jokabsafetyna.com i'm not sure the mod rewrite is working properly. Could you please check that it works as desired? If it works i have a lot of other web sites' .htaccess files to update.

#3 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 08 November 2005 - 09:45 AM

Hi

It doesn't seem to be working on your website. Two things:

1. Post your .htaccess code so we can double check it

2. Make sure your server supports mod_rewrite. Some don't.

#4 wiser3

wiser3

    Gravity Master Member

  • Members
  • 227 posts

Posted 08 November 2005 - 09:57 AM

1.The code:
RewriteCond %{HTTP_HOST} !^www.jokabsafetyna.com

RewriteRule (.*) http://www.jokabsafetyna.com/$1 [R=301,L]

2. Not sure how to check if mod_rewrite is supported. In my cpanel i see this listed as up "exim (exim-4.50-1_cpanel_smtpctl_av_rewrite_mm2_mmmtrap_exiscan_md5pass)" What am i looking for? Your tutorial mentions using the phpinfo function, where can i get that code snippet?

#5 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 08 November 2005 - 10:20 AM

The phpinfo() snippet is very easy: Create a PHP file and paste in the following:


<?php

phpinfo();

?>


EDIT

OK. Here is what I forgot in the tutorial ;)


RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.mysite.com [nc]

RewriteRule (.*) http://www.mysite.com/$1 [R=301,L]


Notice the essential missing bit is the RewriteEngine On line. I also added the [nc] to make case insensitive.

#6 wiser3

wiser3

    Gravity Master Member

  • Members
  • 227 posts

Posted 08 November 2005 - 11:40 AM

I ran the phpinfo function, got back lots of info - no idea what i'm looking at ;)

Here's my new htaccess code, it still doens't seem to work:
RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.jokabsafetyna.com [nc]

RewriteRule (.*) http://www.jokabsafetyna.com/$1 [R=301,L]


#7 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 08 November 2005 - 12:37 PM

Can you post the URL to the phpinfo page please?

You can also do it: search the page for "mod_rewrite" (just search for "rewrite"). If it is not listed, then it most likely that the server doesn't have it enabled. Ask your host.

#8 wiser3

wiser3

    Gravity Master Member

  • Members
  • 227 posts

Posted 08 November 2005 - 01:42 PM

"mod_rewrite" appears in the apache table in the row titled 'Loaded Modules'. If it's a loaded module, it should work, shouldn't it?

I don't feel comfortable posting a public link to all my server info.

#9 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 08 November 2005 - 04:42 PM

Hi. Try this modification.


RewriteEngine On

# redirect non-www to www domain

RewriteCond %{HTTP_HOST} ^DOMAIN.com [NC]

RewriteRule (.*) http://www.DOMAIN.com$1 [R=301,L]


Also, make sure you flush your browser's cache before you test if it works!

#10 wiser3

wiser3

    Gravity Master Member

  • Members
  • 227 posts

Posted 08 November 2005 - 05:19 PM

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.jokabsafetyna.com [nc]

RewriteRule (.*) http://www.jokabsafetyna.com/$1 [R=301,L]

This worked once i cleared my cache. Thanks. Hopefully they'll get higher rankings out of this. I've always been puzzled about why that site didn't rank better.

#11 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 08 November 2005 - 06:29 PM

So it was the cache all along. You got me worried there! Glad it's working now.

#12 Connie

Connie

    Ready To Fly Member

  • Members
  • 16 posts

Posted 08 November 2005 - 07:24 PM

Down load http://www.cyberspyder.com/. It's free and you can check your header response. Only problem with web bug that I have found by default the header response is HTTP 1.0. You will need to change that to HTTP 1.1.

#13 krissydb

krissydb

    Ready To Fly Member

  • Members
  • 23 posts

Posted 12 December 2005 - 03:19 PM

I have about 15 domain names pointed to my main site. Do I have to go into each domain, set up a hosting account and upload a 301 redirect? I am on a UNIX platform, Network Solutions is my hosting provider and I read somewhere that a cname change will work as well but I don't really know what I'm doing. Suggestions?

#14 krissydb

krissydb

    Ready To Fly Member

  • Members
  • 23 posts

Posted 12 December 2005 - 03:30 PM

The other thing...I see lots of references to going in and changing the .htaccess file.

Are people referring to the .htaccess file for my main site or do I need to go into all 15 sites and change the .htaccess file and if they are currently just pointed and not hosted do each of those 15 even HAVE an .htaccess file?

#15 krissydb

krissydb

    Ready To Fly Member

  • Members
  • 23 posts

Posted 21 December 2005 - 11:04 AM

Anyone, anyone...still haven't been able to figure out how this would work.

To recap-15 domains pointed to main using 200 OK - don't want to get main site banned in the search engine...

Do I need an .htaccess file for each of the domain names to put in a 301 redirect? Most of the articles I have read on the subject simply suggest redirecting from the .htacess file but this is in context to pages on the same domain I think as opposed to what I am trying to do, redirect other domain names to my main site.

If I DO indeed need a .htaccess file for each domain name, would I then need to establish a hosting account and userd id and password and root folder for each domain name for this to work? Right now NetSol is just "pointing" them.

If I do need to jump through all these hoop (and from my interpretation it looks very much like I do) and I don't want to do that are there any suggestions as to an alternative to make this work without getting me banned?

#16 Ron Carnell

Ron Carnell

    Honored One Who Served Moderator Alumni

  • Invited Users For Labs
  • 2062 posts

Posted 21 December 2005 - 11:19 AM

You don't need a hosting account for each domain name, but you do need at least one hosting account for the collective.

Get a new hosting account for one of the fifteen domains, then "point" all of them to that account. At that point, all of them will be returning 200 status codes, just as they are now, but they won't be pointing to your main domain. You can then implement a 301 redirect from that domain to the main domain. The result will be that all 15 domains end up where you want them to go and return a 301 status in the process.

There are actually easier and better ways to do this in Apache, but you pretty much have to be running your own server before those ways become available. There's no host of which I'm aware that gives people that level of access. (Hey, Server Admins, there's a need just looking to be filled!)

#17 kensplace

kensplace

    Time Traveler Member

  • 1000 Post Club
  • 1497 posts

Posted 21 December 2005 - 10:38 PM

To test any 301 redirection, make sure you clear your browser's cache first! Otherwise, you won't see if it worked or not.

This is especially true if using the FireFox web browser, you get an error stating that the URL redirection limit has been reached.


Would that mean that if a redirect is done on a site that already has repeat visitors, they wont be able to access the site anymore until they clear the cache? Which could lead to losing a lot of existing visitors?

Or does the problem just naturally clear itself up in time, with the increased results from search engines weighing out any problems of that nature?

#18 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 22 December 2005 - 05:07 AM

Would that mean that if a redirect is done on a site that already has repeat visitors, they wont be able to access the site anymore until they clear the cache? Which could lead to losing a lot of existing visitors?

Or does the problem just naturally clear itself up in time, with the increased results from search engines weighing out any problems of that nature?

View Post



What I see if I don't clear the cache is one of two things:

1. An error saying that the redirection limit has been exceeded.

2. A time out.

This, of course, will clear in time as the browsers, but repeat visitors will probably see the same errors till they clear their cache.

New visitors are unaffected.

I would be interested in hearing if there are work-arounds for this...

#19 eKstreme

eKstreme

    Hall of Fame

  • 1000 Post Club
  • 3399 posts

Posted 22 December 2005 - 05:18 AM

For the record, I just found Google's documentation regarding www and non-www websites.

From their sitemaps blog: Inside Google Sitemaps: www vs non-www versions of a site

From their help center: Why does my site have two different listings in Google: site.com and www.site.com? (title slightly edited because the forum parses the examples as URLs!)

I'll be adding these to my tutorial.

Edited by eKstreme, 22 December 2005 - 05:21 AM.


#20 Ruud

Ruud

    Hall of Fame

  • Hall Of Fame
  • 4887 posts

Posted 22 December 2005 - 05:53 AM

If the page is still in cache it is possible that the browser serves the page from cache. That means no actual request to the server is made - so no rewrite takes place.

Redirect limit exceeded cannot happen in such a case. If you get such an error there is something seriously wrong with your redirect or chain of redirects.

Likewise a timeout should not happen. If a timeout occurs it means your browser is indeed talking with the server and the caching is no problem.

On that note, all browser perfom a display refresh with F5 while CTRL + F5 forces a true refresh (re-request the page and all its files from the server).

#21 JohnMu

JohnMu

    Honored One Who Served Moderator Alumni

  • Hall Of Fame
  • 3518 posts

Posted 22 December 2005 - 06:19 AM

Hi Dr. eKstreme!
That posting is specifically for Google Sitemaps users -- if you want a pseudo-official stand on www/non-www, you might want to link to Matt's Bacon Polenta-page (that's the only way I can remember the URL): http://www.mattcutts.../bacon-polenta/

The proper procedure (assuming that you want www.domain.com to show up) is to make domain.com do a permanent (301) redirect to www.domain.com.


Cheers
John

#22 TymArtist

TymArtist

    Ready To Fly Member

  • Members
  • 33 posts

Posted 16 March 2006 - 11:25 AM

If you don't mind, I'd like to give a little something extra to this post even though it might not be relevant to the tutorial...You can feel free to add this.

(By the way, after reading my post it seems like incoherent rambling of someone who's researched 301 redirects a little too much haha)

First off, to remain relevant - the original redirect we were using in our .htaccess file (that you should NOT use!) was...

Redirect 301 http://domain.com http://www.domain.com
Even though it does a redirect you still end up at http://domain.com.

As a second note, if you're using PHP in your code and still want the files to be .html instead of .php, you can do so with an additional 301 and still use the redirect featured in this tutorial without a problem.

I'd like to post the code because several experience web folk I've talked to about this had no clue you could do such a thing. Just use this in your .htaccess file...

AddType application/x-httpd-php .html
And if you want to redirect anyone trying to go to a .php page to the new .html extension (no need for the first two lines if you've already used them once)...

Options +FollowSymlinks
RewriteEngine on
RewriteRule (.+)\.php$ /$1\.html [R=301,nc]
Pretty cool huh?

Edited by TymArtist, 16 March 2006 - 01:13 PM.


#23 pinbrook

pinbrook

    Gravity Master Member

  • Members
  • 213 posts

Posted 29 April 2006 - 01:55 PM

Get a new hosting account for one of the fifteen domains, then "point" all of them to that account. At that point, all of them will be returning 200 status codes, just as they are now, but they won't be pointing to your main domain. You can then implement a 301 redirect from that domain to the main domain. The result will be that all 15 domains end up where you want them to go and return a 301 status in the process.


I'm also trying to sort out the difference between domain alias and redirect to determine how best to set my domains up.

Assuming I have mydomain.co.uk as the main site, I want to "point" mydomain.com to the co.uk

My hosting panel allows me to alias the com. I've used http://www.seoconsul...ols/headers.asp to determine that i get a 200 status code returned when i use alias

Once my domain is alias ed I don't have an option to do 301. I can only use 301 if the domain is set up as a separate site.

So my question is should I host the site to ensure I can redirect to get a 301 status code or is the 200 status code just as valid for SEO purposes

Additionally it has been suggested that I could use custom DNS and use the cname record - could anyone explain this option also.

TIA

Edited by pinbrook, 29 April 2006 - 02:03 PM.


#24 stinhambo

stinhambo

    Gravity Master Member

  • Members
  • 142 posts

Posted 23 May 2006 - 01:48 AM

I have just created an entry in my .htaccess to deprecate the www and instead revert to the non-www address.

Take a look at this site for more information -

No WWW Page


By the way the code I used is

RewriteEngine on
RewriteCond %{HTTP_HOST} !^easyresume.com.au$ [NC]
RewriteRule (.*) http://easyresume.com.au/$1 [R=301,L]

Hope this helps you out!



RSS Feed

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users