Server Side Redirects - Navigating Google

Server Side Redirects - Navigating Google

Often, we want to redirect users to different pages on our sites for many reasons such as pages have been renamed, or no longer on our server. The quick fix is to do a meta redirect inside the page, but this does not create a 301 permanent redirect and Google will not associate the new page with the old page, nor will they pass the link juice to the new page.

We'll be discussing two ways to redirect for the Linux platform and PHP. The first is updating your .htaccess file and the other is adding code to your page header. For in-depth reading on the .htaccess file, please refer to the Apache tutorial.

Tool: You need a headers checking tool, and one can be found at SEObook.com This will tell you if the site is a redirect with a 201 temp, or 301 perm, or if the site is ok 200.

You want to redirect one page to a new page on your site. You can do this very simply by using one of these to methods.

.htaccess: redirect 301 /old-page.php http://www.Your-Site.com/new-page.php

PHP Header: this will go in the very top of the old page. Note: no white spaces can come before a header call. You will need no other code on this page as the header will redirect before any other code is executed.
            <?php
             header('Location: http://www.Your-Site.com/new-page.php',TRUE, 301);
            ?>
You will also want to make sure you main URL structure is the www version rather than the http version.
http://www.Your-Site.com GOOD

http://Your-Site.com BAD

To do this, you will have have to add the following script into the .htaccess file.

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

If the RewriteEngine on is not already declared in the .htaccess file, you will need to declare it. The advantage is that Google will see the www and non www as two different pages, both having page rank and both competing against each other for keywords. Combine their strength and rank better!

Note: be sure to always link to the www version within your site also. This will help Google with which one you want to use. You can also tell Google in the Google Webmaster Tools.

Tip: Never link to the index.php page but always to the root directory.
http://www.Your-Site.com/index.php BAD
http://www.Your-Site.com/ GOOD

For those astute readers, you will notice the PHP Header redirect can be used for 404 Page Not Found pages. Instead of having a page that says sorry, the page you are looking for is no longer found on this site. Use the above PHP header redirect to redirect them back to the home page while also saving that link juice by using the 301.

You will need to add an error doc line to your .htaccess page.
ErrorDocument 404 http://www.Your-Site.com/error.php
And then place the PHP redirect within that error.php page.

If you want to really get fancy, you can run some logic on that error page before you process it. You can look at the URL being passed to the page, parse it, and try to determine where the visitor wanted to go. Say they were trying to find the about-us page and tried aboutUs instead. You can script out the code to look for variances of about-us and redirect to the proper page. There are lots of variances, so we won't cover them here. If you want to read more, visit W3Schools.

Next time I will be discussing the all important links, those on your page, and those off your page.

No comments:

Post a Comment

Thanks for Comment.