<

Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x

How websites can be redirected?

Published on
13,532 Points
4,532 Views
Last Modified:
Introduction

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

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} !^http://201.192.1.168 [NC]
RewriteRule ^.*$ http://www.domain.com/ [R,L]
0
Comment
Author:torakeshb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
 

Administrative Comment

by:Keith Alabaster
Published - thanks :)

Keith_Alabaster
Page Editor
0
 
LVL 7

Expert Comment

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

Featured Post

Stressed Out?

Watch some penguins on the livecam!

Join & Write a Comment

Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
How to Install VMware Tools in Red Hat Enterprise Linux 6.4 (RHEL 6.4) Step-by-Step Tutorial
Other articles by this author
Suggested Courses

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month