301 redirect is the most efficient and Search Engine Friendly method for webpage redirection. It’s not that hard to implement and it should preserve your search engine rankings for that particular page. If you have to change file names or move pages around, it’s the safest option. The code “301″ is interpreted as “moved permanently”. If been looking around for the ways on how to do this. So this is what i’ve found:
1 2 3 4 5 6 | <script runat="server"> private void Page_Load(object sender, System.EventArgs e){ Response.Status = "301 Moved Permanently"; Response.AddHeader("Location","http://www.new-url.com"); } </script> |
1 2 3 4 5 6 | <%@ Language=VBScript%> <% Response.Status="301 Moved Permanently" Response.AddHeader "Location","http://www.new-url.com/" Response.End %> |
1 2 3 4 5 | <?php Header( "HTTP/1.1 301 Moved Permanently" ); Header( "Location: http://www.new-url.com" ); exit(); ?> |
The code belew, which you place into a file called .htaccess in the root folder of your old domain, will ensure that all your directories and pages of your old domain will get correctly redirected to your new domain.
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)
1 2 3 | Options +FollowSymLinks RewriteEngine on RewriteRule (.*) http://www.new-domain-name.com/$1 [R=301,L] |
NOTE: REPLACE www.new-domain-name.com in the above code with your actual domain name.
NOTE: This .htaccess method of redirection works ONLY on Linux servers having the Apache Mod-Rewrite moduled enabled.
Create a .htaccess file with the below code, it will ensure that all requests coming in to domain.com will get redirected to www.domain.com
As with the last example, 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)
1 2 3 4 | Options +FollowSymlinks RewriteEngine on rewritecond %{http_host} ^domain.com [nc] rewriterule ^(.*)$ http://www.domain.com/$1 [r=301,nc] |
NOTE: Replace domain.com with your domain name
NOTE: Both of these last examples ONLY works on Linux servers having the Apache Mod-Rewrite moduled enabled.
And there you have it. You can Test your redirection with Search Engine Friendly Redirect Checker
This entry was posted on Monday, March 3rd, 2008 at 2:38 pm and is filed under Linux, Tutorial. You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.
Title : My Boy (1)
Media: Canon EOS 350D DSLR, Adobe Lightroom, Photoshop
Description : A day out in the park with my world.
Title : Tasmania Corrective Services Badge
Media: Adobe Illustrator, Stitch
Description : Badge for the Canine Drug Detection Unit
Title : Webb Martin Consulting Website Concept 1
Media: Blog/Website, flash, css, xhtml, php
Description : Website deisgn for Webb Martin Consulting
Title : Webb Martin Website Design Concept
Media: Wordpress, CSS, xhtml, php
Description : Concept website design for Webb Martin.