Detailed 301 Redirect and implementation method

Source: Internet
Author: User
Tags change domain name

One, what is 301 redirect

301 Redirect (or call 301 jump, 301 turn) is a user or search engine spider to the site server to make access requests, the service returns the HTTP data stream header part of the status code of one, indicating that this site is permanently transferred to another address. Other common status codes include: 200 (indicating everything is ok), 404 (Web page does not exist), 302 (temporary steering), 500 (internal program error);

In addition to the 301 turn, the URL steering has other methods, such as 302 steering, JavaScript steering, php/asp/cgi program steering, Meta refresh, and so on.

301 redirects have an irreplaceable effect on search engine optimization. Consolidate the URL of the canonical version with 301 redirects, regain weight, and prevent duplicate content of search results. From the perspective of SEO, 301 redirection is the most feasible way to redirect URLs.

Ii. under what circumstances use 301 redirect

Website revision often need to use 301 Redirect: such as the site change domain name, change the structure of the Web directory, the page is moved to a new address, the extension of the page changes, such as the need to change. php to. html. In this case, if you do not redirect, then the user's favorite or search engine database in the old address can only give access to the customer will also get a 404 page error message, access traffic lost in vain. Using 301 redirects not only allows the page to automatically jump, telling the user that you have changed the new URL. Also tell the search engine, this is the real URL, the search engine only redirect after the new URL index, while the old address weight will be transferred to the new address, so that the site will not be ranked because of changes in the impact.

A Web site registers multiple domain names and requires 301 redirects for users who access those domains to automatically jump to one of the primary domains. This is done to avoid causing massive duplication of content, which is punished by search engines. Because in the search engine view, each domain name is a separate station, multiple domain names point to the same station, will be identified as the site of the same, content replication, light is not included into the sandbox period, the weight is directly K.

301 redirects are also required to implement URL normalization

Suppose there are several URLs:

Http://www.admin10000.com/index.html

Http://admin10000.com

Http://admin10000.com/index.html

All do 301 Redirect to Http://www.admin10000.com (the selected canonical URL), the search engine will know that http://www.admin10000.com is a normalized URL, and will be the above column of the URL weights passed to the normalized URL.

At present, Google will pass most of the weight, but not the absolute weight. Baidu will pass the weight of ownership. Google's 301 recognition, response, and completion of weight transfer, it takes 1-3 months. Baidu's 301 treatment is more conservative, the old and new URLs will exist in the database for a long time.

Third, Apache server implementation 301 redirect

If your website uses a lamp (Linux + Apache + MySQL + PHP) host, you can use Apache's mod_rewrite to rewrite or redirect URLs. The following steps are required:

1, first ensure that the Mod_rewrite function is turned on.

Open the Apache installation directory with a text editor \conf\httpd.conf, find "#LoadModule rewrite_module modules/mod_rewrite.so" This line, remove the front "#";

Continue to find "allowoverride None", modified to "allowoverride all";

Then, restart Apache.

2. Place a. htaccess file in the root directory of the site where you need URL redirection, the file name is. htaccess,windows cannot be created directly, you can save it as a notepad.

3. Redirect to the desired page in. htaccess with regular expressions. Examples are as follows:

REDIRECT Top-level domain 301 without www to a domain with www

    Options +followsymlinks    rewriteengine on    rewritecond%{http_host} ^admin10000.com [NC]    rewriterule ^ (. *) $ http://www.admin10000.com/$1 [l,r=301]

redirect page 301 to another page

    Options +followsymlinks    rewriteengine on    rewriterule ^/oldpage.html$/newpage.html[nc,l,r=301]
Four, the IIS server do 301 redirection setting method

Example: Jump admin10000.com to Www.admin10000.com

1, create a new site, corresponding directory such as D:\site. The site is primarily used for steering, the directory can be empty, and no files are required. Then bind the site to jump to the domain name admin10000.com,

2. In IIS, select the site that we just established, right-click, properties, home directory, select Redirect to, enter another Web address that is bound to the www.admin10000.com domain name (this site contains the site content). The address entered is: http://www.admin10000.com$s$q, and note the 2 options below, "persistent redirection options for resources" and "exact URLs entered above" are selected. Such as:

For $s$q characters, here's an explanation:

$S to pass the suffix of the requested URL to the new URL. The suffix is the portion of the initial URL that is reserved after the redirected URL is replaced.

If the exact URL entered above option is not selected, the name of the result destination URL will have the name of the requested file (as the folder name) and the file name itself.

$Q Pass parameters (such as the QueryString parameter) from the initial URL to the new URL, including the question mark (?).

If you do not add $S $q characters, the inside of the page 301 will jump to the home page, plus the $s$q character is the purpose of the internal pages can also be accurate to jump to the corresponding internal page of the new domain name.

All right, this completes the 301 permanent redirection setting, and it's best to test the success of the 301 redirect after it's set up. The Webmaster Tools HTTP Status Tool (http://tool.chinaz.com/pagestatus/) can be found, if the return status of the check is 301 indicates that you have succeeded.

V. Using Isapi_rewrite to implement IIS 301 redirection

Isapi_rewrite is a third-party URL rewrite component for IIS. It is based on regular expression, similar to Apache mod_rewrite function, not only can implement URL rewriting, also can achieve 301 redirect.

The Isapi_rewrite component has free (Lite) and commercial (full), the free version only supports global httpd.conf configurations, cannot be set individually for each site, and the Business Edition lets you customize URL rewrite rules for each site, as long as the Httpd.ini Put it in the root of the site to take effect.

Use the Isapi_rewrite 2.x or the latest version 3.0 (which is compatible with Apache's mod_rewrite syntax), while the earlier 1.x version does not support the 301 redirection feature.

Here's an example:

1. Redirect the top-level domain 301 without www to the domain with www

# Isapi_rewrite 2.x version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteCond Host: ^admin10000\.com$r Ewriterule (. *) http://www.admin10000.com$1 [I,RP]
# Isapi_rewrite 3.0 Version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteCond%{http:host} ^admin10000 \.com$rewriterule (. *) http://www.admin10000.com$1 [nc,r=301]

2.301 turns between different domain names

# Isapi_rewrite 2.x version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteCond Host ^www\.test10000\.co M$rewriterule (. *) http://www.admin10000.com$1 [I,RP]
# Isapi_rewrite 3.0 Version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteCond%{http:host} ^www\.test1 0000\.com$rewriterule (. *) http://www.admin10000.com$1 [nc,r=301]

3. redirect page 301 to another page

# Isapi_rewrite 2.x version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteRule ^/oldpage.html$/newpage . html[i,o,rp,l]
# Isapi_rewrite 3.0 Version [isapi_rewrite]# 3600 = 1 hourcacheclockrate 3600RepeatLimit 32RewriteRule ^/oldpage.html$/newpage . Html[nc,l,r=301,o]
Vi. implement 301 redirects in the Web daemon

If the page is asp/php/jsp/asp.net you can then do 301 redirects in the background code.

But I personally do not recommend this, because on the server do 301 jump is on your page before the execution of the jump, high efficiency. And in the program code to do 301, to the head of each page to add a steering code, more trouble.

Examples are as follows:

1.301 Redirects under PHP

<?  Header ("http/1.1 301 Moved permanently"); Header ("location:http://www.admin10000.com");? >

2.301 redirects under ASP

<%@ language=vbscript%><% response.status = "301 Moved Permanently" Response.AddHeader "location", "http://www . admin10000.com "%>

3, ASP. NET of 301 redirects

<script runat= "Server" >private void Page_Load (object sender, System.EventArgs e) {      response.status = "301 Moved permanently ";      Response.AddHeader ("Location", "http://www.admin10000.com");} </script>

4.301 redirects under JSP

<%  response.setstatus (301);  Response.setheader ("Location", "http://www.admin10000.com");  Response.setheader ("Connection", "close");%>

Tip: If the return header has only location, but does not explicitly mention the status code, it means a 302 temporary redirect. Please remember in your heart. For example, the following are 302 redirects:

302 redirects under PHP

<?   PHP Header ("location:http://www.admin10000.com"); >

302 redirects under ASP

<% Response.Redirect "http://www.admin10000.com/"%>

ASP. NET 302 Redirection

<script runat= "Server" >  private void Page_Load (object sender, System.EventArgs e)  {     Response.Redirect ("http://www.admin10000.com");  } </script>

302 redirects under JSP

<%    response.sendredirect ("http://www.admin10000.com");%>

Summary:301 Redirects are the most friendly way to turn a Web site to a search engine. Of the many redirection technologies, 301 Permanent redirection is one of the safest ways to do this, and it's also a great solution. Whether it is a permanent URL change, or multiple format URL normalization is inseparable from the 301 redirect.

Detailed 301 Redirect and implementation method

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.