How to set a 301 redirect


You've just redesigned some pages of your web site. The pages have high search engine rankings that you don't want to lose. How can you safely redirect web site traffic from your old pages to the new pages without losing your rankings? You can do this by using a " 301 redirect " So , What actually is this “301” ?

A 301 redirect allows visitors and search engines to access a web page after it has been moved. If you have changed the domain name of your web site or changed the file names of pages, then you need to link to the new URLs for visitors and search engine spiders. The 301 permanent redirect is the most search engine-friendly method of redirection to the new URL or page and is the current standard for SEO purposes.

You can use it in several situations, including:
·         to redirect an old website to a new address
·         to setup several domains pointing to one website
·         to enforce only one version of your website (www. or no-www)
·         to harmonize a URL structure change

PHP Single Page Redirect

In order to redirect a static page to a new address simply enter the code below inside the index.php file.
<?php
header("HTTP/1.1 301 Moved Permanently");
header("Location: http://www.newdomain.com/page.html");
exit();
?>

PHP Canonical Redirect

The Canonical 301 Redirect will add (or remove) the www. prefixes to all the pages inside your domain.
<?php
if (substr($_SERVER['HTTP_HOST'],0,3) != 'www') {
header('HTTP/1.1 301 Moved Permanently');
header('Location: http://www.'.$_SERVER['HTTP_HOST']
.$_SERVER['REQUEST_URI']);
}
?>
Apache .htaccess redirect

 1.To create a .htaccess file, open notepad, name and save
the file as .htaccess (there is no extension).

2. If you already have a .htaccess file on your server,
download it to your desktop for editing.

3. Place this code in your .htaccess file:

redirect 301 /old/old.htm http://www.you.com/new.htm

4. If the .htaccess file already has lines of code in it,
skip a line, then add the above code.

5. Save the .htaccess file

6. Upload this file to the root folder of your server.

7. Test it by typing in the old address to the page you've
changed. You should be immediately taken to the new
location.

ASP .NET Redirect :
<script runat="server">
private void Page_Load(object sender, System.EventArgs e)
{
Response.Status = "301 Moved Permanently";
Response.AddHeader("Location","http://www.new-location.com");
}
</script>

Canonical Redirect using IIS 7.0

For this to work, you need to download and enable the URL Rewrite module for IIS 7. Then the following code is used in the ASP.NET web.config file:
<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="Redirect to WWW" stopProcessing="true">
          <match url=".*" />
          <conditions>
            <add input="{HTTP_HOST}" pattern="^domain.com$" />
          </conditions>
          <action type="Redirect" url="http://www.domain.com/{R:0}"

               redirectType="Permanent" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>


2 comments:

nice post dude..am gonna do the same for my blog too... :)
http://atom-news.blogspot.com/

As soon as when a time, college students were actually obligated to perform all the things themselves. https://eliteessaywriters.com/review/kibin-com

Post a Comment

HITS >>

Free Hit Counters

Bloggers.com

Review this blog on Bloggers.com