How websites can be redirected?

AID: 8789
  • Status: Published

3240 points

  • Bytorakeshb
  • TypeTutorial
  • Posted on2011-12-07 at 22:54:01
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]

Comments

Expert Comment

by: ZShaver on 2012-01-05 at 22:25:20ID: 34194

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/');
?>

Add your Comment

Please Sign up or Log in to comment on this article.

Join Experts Exchange Today

Gain Access to all our Tech Resources

Get personalized answers

Ask unlimited questions

Access Proven Solutions

Search 3.2 million solutions

Read In-Depth How-To Guides

1000+ articles, demos, & tips

Watch Step by Step Tutorials

Learn direct from top tech pros

And Much More!

Your complete tech resource

See Plans and Pricing

30-day free trial. Register in 60 seconds.

Loading Advertisement...

Top Linux Experts

  1. arnold

    331,375

    Wizard

    750 points yesterday

    Profile
    Rank: Genius
  2. woolmilkporc

    279,119

    Guru

    2,668 points yesterday

    Profile
    Rank: Genius
  3. farzanj

    132,548

    Master

    0 points yesterday

    Profile
    Rank: Genius
  4. KeremE

    109,627

    Master

    0 points yesterday

    Profile
    Rank: Genius
  5. duncan_roe

    105,116

    Master

    0 points yesterday

    Profile
    Rank: Genius
  6. hanccocka

    99,734

    Master

    1,500 points yesterday

    Profile
    Rank: Genius
  7. legolasthehansy

    74,904

    Master

    0 points yesterday

    Profile
    Rank: Guru
  8. xterm

    65,407

    Master

    0 points yesterday

    Profile
    Rank: Sage
  9. Papertrip

    59,708

    Master

    0 points yesterday

    Profile
    Rank: Sage
  10. DaveBaldwin

    55,260

    Master

    0 points yesterday

    Profile
    Rank: Genius
  11. TobiasHolm

    46,700

    0 points yesterday

    Profile
    Rank: Sage
  12. rindi

    43,404

    0 points yesterday

    Profile
    Rank: Savant
  13. ahoffmann

    41,621

    0 points yesterday

    Profile
    Rank: Genius
  14. noci

    40,754

    0 points yesterday

    Profile
    Rank: Genius
  15. gerwinjansen

    38,789

    0 points yesterday

    Profile
    Rank: Sage
  16. Darr247

    38,657

    0 points yesterday

    Profile
    Rank: Genius
  17. chandranjoy

    36,828

    0 points yesterday

    Profile
    Rank: Master
  18. torakeshb

    33,696

    0 points yesterday

    Profile
    Rank: Master
  19. pfrancois

    33,520

    0 points yesterday

    Profile
    Rank: Guru
  20. un1x86

    30,652

    0 points yesterday

    Profile
    Rank: Master
  21. maeltar

    30,550

    0 points yesterday

    Profile
    Rank: Guru
  22. ozo

    24,100

    0 points yesterday

    Profile
    Rank: Savant
  23. jgiordano

    23,700

    0 points yesterday

    Profile
    Rank: Guru
  24. for_yan

    23,600

    1,000 points yesterday

    Profile
    Rank: Genius
  25. bummerlord

    23,300

    0 points yesterday

    Profile
    Rank: Master

Hall Of Fame