[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More


How websites can be redirected?

Published on
13,842 Points
Last Modified:

We as admins face situation where we need to redirect websites to another. This may be required as a part of an upgrade keeping the old URL but website should be served from new URL. This document would brief you on different ways can do the website redirection.

Redirect using "Meta Refresh Tag" method

Create a simple html file with the below code. This will redirect the URL to http://newwebpage.com

HTML Syntax: <META http-equiv=”refresh” content=”<time>[;URL=<new url>"]>

...head section stuff (Title, Description,etc.)...
<meta http-equiv="refresh" content="0;url=http://newwebpage.com">

Meta-tag method is on of easiest way to achieve the redirect the web pages. But it has some disadvantages. Crawlers used in search engines will not keep the old rank in the new web page. Disadvantage in "Meta Refresh Tag" method can be solved using 301 redirect.

What is 301 redirect.

301 redirect, interpreted as “moved permanently”, is a method used to redirect webpages while preserving your search engine rankings. There are different ways to achieve this.

Please note my examples are based on Apache web server.

Redirect with .htaccess and Mod_Rewrite

The easiest way to achieve redirection is using .htaccess, since it doesn’t require access to server. We can make use of FTP access and upload the .htaccess file.

Scenario 1.

Simple 301 redirect accessing a page to a newwebpage.

RewriteEngine On
Redirect 301 /mypage.htm http://newwebpage.com
Save the file and upload the .htaccess file to the root of the domain that hosts the old page. This will do a permanent redirect the page to the newwebpage.com and get the advantage of old web site ranking as well.
Scenario 2

www and non-www are not same for search engines

There are two ways to view most sites, that’s the www and non-www version www.domain.com and it basically became the standard way to access a site via a browser. However it’s not the only way, some sites can be browsed using http://domain.com which in the non-www version.

This has led to problems with search engines like Google indexing both versions resulting in duplicate content and sharing link benefit problems. Some webmasters link to the www version and others the non-www, search engine spiders follow the links and spider the site twice.

.htaccess file to redirect non-www site to www

Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST}   !^www\.domain\.com [NC]
RewriteRule ^/(.*)         http://www.domain.com:%{SERVER_PORT}/$1 [L,R]

Scenario 3

Redirect Homepage of a site according to the ``User-Agent:'' header of the request

You might have noticed some websites will load different pages when browsed from different browsers. The simple logic is to have multiple websites and have the below in .htaccess file.

RewriteCond  %{HTTP_USER_AGENT}  ^Mozilla
RewriteRule  ^/$                 /homepage.max.html  [L]

RewriteCond  %{HTTP_USER_AGENT}  ^Lynx
RewriteRule  ^/$                 /homepage.min.html  [L]

RewriteRule  ^/$                 /homepage.std.html  [L]

Scenario 4

Protecting your images and files from linking

If you do not want other webmasters linking to your website files and images as inline-images on their pages use the below in .htaccess file.

RewriteEngine On
RewriteCond %{HTTP_REFERER} !^$ [NC]
RewriteCond %{HTTP_REFERER} !^http://domain.com [NC]
RewriteCond %{HTTP_REFERER} !^http://www.domain.com [NC]
RewriteCond %{HTTP_REFERER} !^ [NC]
RewriteRule ^.*$ http://www.domain.com/ [R,L]

Administrative Comment

by:Keith Alabaster
Published - thanks :)

Page Editor

Expert Comment

you can also redirect using a header redirect, sending a header to the browser to have it switch locations...
e.g. in php...
header('Location: http://www.example.com/');

Featured Post

10 Tips to Protect Your Business from Ransomware

Did you know that ransomware is the most widespread, destructive malware in the world today? It accounts for 39% of all security breaches, with ransomware gangsters projected to make $11.5B in profits from online extortion by 2019.

Join & Write a Comment

Connecting to an Amazon Linux EC2 Instance from Windows Using PuTTY.
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Other articles by this author
Next Article:

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month