WebPage Redirection

There are a number of ways of doing this. The most commonly and easiest to use are meta refreshes and javascript redirects. a better method would be to use a server-side redirect (PHP, ASP, .Net). I will list examples of each and also some of the disadvantages each have.

Meta Refresh
Using this meta tag in your html page will Redirect the page after a given interval to to the address specified.

This code will redirect the page to ibnmasud.com after 5 seconds:
<meta http-equiv=\"refresh\" content=\"5;url=http://ibnmasud.com\" />
Setting the interval to 0 will redirect to ibnmasud.com immediately:
<meta http-equiv=\"refresh\" content=\"0;url=http://ibnmasud.com\" />
Disadvantages:

  • Using the back button will take you back to the redirect page which will then redirect you again. Firefox, Opera, and Safari ignore this behavior and IE users can double-click the back button. Also referred to as \”brokeback buttons\”.
  • Can easily be disabled on the client side. If disabled, the page will not redirect.

Javascript
Javascript gives you a lot more flexibility in redirecting pages.

Location.href Method
Including this script on a page will immediately redirect visitors to the URL entered. This method creates two items in the browsers history. One for the page including this script and one for the page that this page will redirect to.
<script type=\"text/javascript\">
window.location.href=\"http://nsfw.ibnmasud.com/\";
</script>

So it works the same way as a meta refresh in that it can lead you into a loop if you press the back button.

Location.replace Method
The Location.replace method solves the loop problem by replacing the content of the browsers history with the redirected page\’s address, i.e, only one item is created in the browsers history.
<script type=\"text/javascript\">
location.replace(\\\'http://www.example.com/\');
</script>

Disadvantages:

  • Google will not index pages redirected using javascript.
  • Can easily be disabled on the client side. If disabled, the page will not redirect.

PHP
A basic permanent (301) redirect in PHP uses the code below:
<?PHP
// This header tells the client the HTTP status code of the page
header(\"HTTP/1.1 301 Moved Permanently\");
// The client must then be informed where the URI is now located
header(\"Location: http://www.example.com/example\");
?>

Using .htaccess for Redirection

When using the Apache web server, directory-specific .htaccess files (as well as apache\’s main configuration files) can be used. For example, to redirect a single page:

Redirect 301 /oldpage.html http://www.example.com/newpage.html

To change domain names:

RewriteEngine On
RewriteCond %{HTTP_HOST} ^.*oldwebsite\\.com$ [NC]
RewriteRule ^(.*)$ http://www.preferredwebsite.net/$1 [R=301,L]

Disadvantages:
Use of .htaccess for this purpose usually does not require administrative permissions, though it can be disabled.

1 Comment

  1. Nabil Khan

    Great post, thanks. I have one comment regarding the HTML redirect. You mentioned in the disadvantages that, “Using the back button will take you back to the redirect page which will then redirect you again. Firefox, Opera, and Safari ignore this behavior and IE users can double-click the back button.”

    I am using this method on my website and after redirection, if I click the back button, it does not take me to the redirect page. I am using firefox. I also check and it work smoothly with IE.

Leave a Reply

Your email address will not be published. Required fields are marked *