Changed Domain Name?
Need to change a file name?
Changed the Script running your Site?
Now basically you have 2 options - create a custom error page or redirect old pages to new in a search engine and user friendly manner.
The problem with custom error page is that it will be irritating to your site visitors as they will need to dig through your site to find the desired page and you may lose site visitors due to their frustration. Also, you may lose rankings on the next search engine update as the file will appear to be non-existent even though it exits with new name/format.
So your best and only option is to redirect your site visitors to new location and also let Search engines know that a particular web-page has moved to a new location permanently. For this purpose 301 redirect is considered the most efficient and Search Engine Friendly method for web-page redirection. It is quite easy to implement and it helps in preserving your search engine ranking.
Different methods to Re Direct Web Pages: --
.htaccess 301 Redirect
This only works on Apache on Linux. Create a file named .htaccess and add following code for moving a single page.
Redirect 301 /oldpage.html http://www.example.com/newpage.html
For moving the entire site add following code –
Redirect 301 / http://www.example.com/
This will move all the traffic from old site to new.
Make sure you replace example.com with your own sites URL.
If you have changed file extensions for your site use following code to redirect your web-pages
RedirectMatch 301 (.*)\.html$ http://www.domain.com$1.php
This will redirect all the pages ending with .html to all the pages ending in .php. For example http://www.domain.com/yourpage.html and redirect it to http://www.domain.com/yourpage.php
301 Redirect Using Apache Mod-Rewrite module
Mod_Rewrite has got to be one of the most usefull modules a server can have in terms of SEO, it allows you to organize the files on your web site in a dynamic yet simple fashion.
Create an .htaccess file and add following code to it
RewriteEngine On
rewritecond %{http_host} ^yoursite.com
rewriteRule ^(.*) http://www.yoursite.com/$1 [R=301,L]
The .htaccess file needs to be placed in the root directory of your old website (i.e the same directory where your index file is placed)
Redirect non-www to www
Options +FollowSymlinks
RewriteEngine on
rewritecond %{http_host} ^domain\.com [nc]
rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc]
This will ensure that all requests coming in to domain.com will get redirected to www.domain.com
301 Redirect Using PHP
Simply add this code to your webpage or script:
header( "HTTP/1.1 301 Moved Permanently" );
header( "Status: 301 Moved Permanently" );
header( "Location: http://www.new-url.com/" );
exit(0); // This is Optional but suggested, to avoid any accidental output
?>
301 Redirect Using IIS
In internet services manager, right click on the file or folder you wish to redirect.
Select the radio button titled "a redirection to a URL".
Enter the page that the page will be redirected to.
Check "The exact url entered above" and the "A permanent redirection for this resource".
Click on 'Apply'.