Apache, Computer Science, Geek, Javascript, Programming, Tutorials

How To Redirect Visitors To Another Site Or Page – Different Techniques & Explanations for Beginners

Redirecting web pages is an oft used term in search engine optimization. In fact, it is important for all webmasters carrying out search engine optimization of their sites to learn about redirecting web pages. Redirecting a page holds much importance in SEO. This is because inbound links to a web page are considered by search engine ranking algorithms while ranking websites. Therefore, one must know what it is meant by redirecting a page and what are the different techniques of redirecting a page.


Redirect Image Via Shutterstock

What is meant by redirecting a page?

Whenever a web browser or search engine crawler requests a page at a particular URL on any web site, the web server on which that site is hosted tries to locate the page at that URL so that it can return the corresponding HTML to the requester. Now if that web page exists then the server returns the HTML needed to render that page . It also returns a 200 HTTP status in the header of the response. With this status, the requesting browser or crawler gets the message that the page was found and its HTML was returned.

Sometimes some web pages need to be deleted or moved to a new location. In such a case, a webmaster has two options. First, he can all all future requests for the old web page to be returned to a 404 HTTP status that indicates that the page could not be found. Second, he can ask the browser or search engine crawler to request the page using a new URL. There is a temporary redirect as well as a permanent redirect.

Advantages of redirecting web pages

1. First of all, a redirect lets a site to inform visitors that the page or entire site has been moved to a different web address. It also tells the visitors that the redirection process is automatic and the new address is displayed on the browser.

2. With the help of a permanent redirect, one can perform actions like switching domains, redirecting a part of the website to a new domain or redirecting a folder on your site to a new folder.

Different techniques to redirect a web page

There are different techniques available for redirecting a web page. Some of these techniques are discussed here in detail.

1. Browser side redirection using Javascript

JavaScript can be used to redirect web pages. This technique is useful as it makes the redirection conditioned. This is how drop down menus are created. You can also redirect a page without a condition. This is used to cloak the content. By cloaking the content, it will still be interpreted by the search engines as they can penetrate through the JavaScript and at the same time users will be swiftly redirected. Redirecting a page using JavaScript is more instant than ‘instant’ meta-refresh redirection if the code is placed in the header because meta-refresh waits for the page to load first. These days search engines know how to look for redirection in Javascript. Therefore, you can choose to encrypt the script or load it from a remote file as per your convenience.

/* example */
window.location = "http://www.google.com/";

2. Browser side redirection using HTML

You can use HTML to redirect a page. Here you can use the meta-refresh tag to redirect a page immediately or after a period of time. However, one thing that should be borne in mind is that some search engines penalize pages that use page redirection technique with short delays. This is because it could appear as a cloaking attempt. Cloaking means that human users are redirected too quickly to read the page. However, this technique can be useful to redirect to a different site of yours or directly to a sponsors page, with your referral code after 350 seconds. The idea behind this is that a surfer has your site in a stack of windows or tabs and as he closes them he will stop at the new page and look at it.

/* example */
<meta http-equiv="REFRESH" content="0;url=http://www.the-domain-you-want-to-redirect-to.com">

3. Browser side redirection using Flash

If you are comfortable working with Flash, then browser side redirection using Flash will be pretty easy for you. To create an instant redirect, you can make your own flash movie with one frame that has a single transparent area in it. Now you need to paste the relevant code into the actionscript pane for that frame. In case you want to redirect after a period of time, you can make a movie of the appropriate length and paste the code into the actionscript pane of the last frame.

/* example */
var url:String = "http://www.google.com"
var urlRequest:URLRequest = new URLRequest(url);
navigateToURL(urlRequest, "_blank");

4. Server side page redirection using PHP

This technique can be useful if you want to redirect to a different page depending on the outcome of a script. With the help of this technique and appropriate skills, you can redirect to a joke page on a Sunday, political news on a Monday, Books review on a Tuesday and so on. However, one thing that you should keep in mind is that you must call the function before any text or HTML is sent to the browser. Redirect will fail with an error message if you call the function after the redirect.

/* example */
header("Location: http://domain.com/");

5. Hidden Browser side redirection using Iframe and JavaScript

When it comes to search engine optimization some people are too wary of search engines finding their pages are redirected. If you are one of those then this is a good method for you. All you need to do is to put an iframe in the page you want to redirect from. After this, in the source attribute of the iframe, put the url of the page you wish to redirect to.

When you do this, the browser loads the new page into the iframe. Then the page is executed in framebreaker and the new page is displayed in place of the one that was originally loading. Thus you can quickly redirect a page using this Javascript technique

6. Server side redirection using .htaccess 301 on Unix servers

Result Code 301 is the only way to redirect to a new page which is properly supported by search engines. It is also known as permanent redirect. With this, Google not only transfers all the traffic but also any page rank to the new page. The .htaccess files are simple text files that contain instructions for the server on your site. You can either have one such file in every directory where it is needed or a single file in the document root directory for the entire site. In case you already have a .htaccess file in your directory then you can simply add any redirects to the top of the file.

/* example */
Options +FollowSymLinks
RewriteEngine on
RewriteRule (.*) http://www.newdomain.com/$1 [R=301,L]

7. Page redirection from any point in a PHP script

The PHP script gives you an option of redirecting your page at any given interval. You may utilize this technique if in case you stumble upon the awkward header which the script may produce sporadically.

/* example */
header("Location: http://domain.com/");
exit;

8. Server side redirection using ASP and ASP.net on windows servers

The only way to redirect to a new page which is properly supported by search engines is Result code 301. And it is known as the permanent redirect. It will make sure that Google transfers not only all the traffic but also any page rank to the new page.

/* example */
/* ASP */
Response.Status="301 Moved Permanently"
Response.AddHeader "Location","http://www.new-url.com/"

/* ASP.NET */

private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-url.com");
}

These are some of the good techniques that you can use to redirect your web pages. Make sure that you use the right code.

You Might Also Like

  • What about if: I need a php code – let’s say he goes to my site: (www.idesignpassion.com/index.html) when he comes back after 2 days – I want him to see (www.idesignpassion.com/index1.html)

    • Hey Frank, not sure why you would do such a thing, but to pull that off you would need to use PHP or Javascript to set Cookies to check to see if the cookie is 2 days old or whatever you are trying to check