How to setup a 301 Permanent redirect

The 301 redirect is a HTTP status code to inform search engines that a page or entire website has been permanently moved to another link on the web. It is most efficient and Seo friendly since you won’t loose any of the search traffic for that page or website

  • In most of the cases webmaster practise 301 redirect to enforce only one version of website because a website named and will be considered two different website by searh engines though they both are same.
  • 301 redirect can also be used to redirect users to a new address from an old adddress or to redirect several domains to one website.
Single page redirect using .htaccess

Inorder to redirect a single page add this code on your .htaccess file. If you don’t have one then open your notepad and save it without an extension naming .the file .htaccess (For Apache Server).

Redirect 301 /oldpage/yourpage.htm

Redirecting visitors from a domain using .htaccess

Use this code in your .htaccess for redirecting from an old domain

Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^ [nc]
rewriterule ^(.*)$$1 [r=301,nc]

Redirecting using PHP single page

Add this code in your Index.php file for Single Page

header(“HTTP/1.1 301 Moved Permanently”);

PHP Canonical 301 Redirecting

To redirect domain from a non www to www add this code in your Index.php

if (substr($_SERVER[‘HTTP_HOST’],0,3) != ‘www’) {
header(‘HTTP/1.1 301 Moved Permanently’);
header(‘Location: http://www.’.$_SERVER[‘HTTP_HOST’]

Found this post useful follow us on Facebook or Twitter to get more updates