RedirectADomain.com - How to set up a 301 Redirect?
Using a 301 redirect is best way to preserve your search engine ranking for a web page or domain name. A redirect is typically used when the page or domain name is moved or replaced with another.
For example, a website say "RedirectADomain.ca" is very well-known and has a high ranking in the search engines. The owner of the website decides to register the domain name "RedirectADomain.com" and use it as the primary domain name for accessing the website. The owner is now concerned about how to notify not only the website visitors but also the search engines of the domain name change but still preserve the site's high search engine ranking. Using the examples below the website owner is able accomplish two tasks, preserve the ranking and redirect website visitors to the new domain name. This method is called a "301 redirect"; the 301 code is a HTTP status code which is interpreted as a "permanently moved". Below you will find how to code a 301 redirect using popular scripting languages.
- ColdFusion
- PHP
- ASP
- ASP.net
- JSP (Java)
- CGI/PERL
- Ruby on Rails
- .htaccess
301 Redirection using ColdFusion
ColdFusion
- <.cfheader statuscode="301" statustext="Moved permanently">
- <.cfheader name="Location" value="http://www.redirectadomain.com/">
301 Redirection using PHP
PHP (PHP: Hypertext Preprocessor)
- <?php
- ?>
301 Redirection using ASP
ASP (Classic Active Server Pages)
- <%@ Language=VBScript %>
- <%
- Response.Status="301 Moved Permanently"
- Response.AddHeader "Location","http://www.redirectadomain.com/"
- %>
301 Redirection using ASP.net
ASP.net
- <script runat="server">
- private void Page_Load(object sender, System.EventArgs e)
- {
- Response.Status = "301 Moved Permanently";
- Response.AddHeader("Location","http://www.redirectadomain.com/");
- }
- </script>
301 Redirection using JSP (Java)
JSP (JavaServer Pages)
- <%
- response.setStatus(301);
- response.setHeader( "Location", "http://www.redirectadomain.com/" );
- response.setHeader( "Connection", "close" );
- %>
301 Redirection using PERL/CGI
Perl (Practical Extraction and Report Language) or CGI (Common Gateway Interface)
- $q = new CGI;
301 Redirection using Ruby on Rails
Ruby or Ruby on Rails
- headers["Status"] = "301 Moved Permanently"
- redirect_to "http://www.redirectadomain.com/"
301 Redirection using .htaccess
.htaccess
- Options +FollowSymLinks
- RewriteEngine on
- RewriteRule (.*) http://www.redirectadomain.com/$1 [R=301,L]: