Explanation 301 redirection and implementation methods, explanation 301 redirection

Source: Internet
Author: User
Tags website server to domain

Explanation 301 redirection and implementation methods, explanation 301 redirection
1. What is 301 redirection?

301 redirection (or 301 redirection) is the header information in the HTTP data stream returned by the service when a user or a search engine spider sends an access request to the website server) A part of the status code, indicating that the URL is permanently transferred to another address. Other common status codes include 200 (indicating that everything is normal), 404 (indicating that the webpage does not exist), 302 (temporary redirection), and 500 (internal program error );

In addition to the 301 redirection, there are other methods for website redirection, such as the 302 redirection, JavaScript redirection, PHP/ASP/CGI program redirection, and Meta Refresh.

301 redirection plays an irreplaceable role in search engine optimization. Use 301 redirection to consolidate the URL of the standard version and regain the weight to prevent duplicate content in the search results. From the perspective of search engine optimization, 301 redirection is the most feasible method for URL redirection.

Ii. When to use 301 redirection

301 redirection is often required for website revisions. For example, if a website domain name is changed, the webpage directory structure is changed, the webpage is moved to a new address, and the webpage extension is changed. If you need to change. php to. html. In this case, if no redirection is performed, the old address in the user favorites or search engine database can only give the visitor a 404 page error message, and the access traffic is lost. Using 301 redirection not only enables automatic page Jump, but also tells the user that you have changed the URL. It also tells the search engine that this is the real URL. The search engine only indexes the new URL after redirection, and transfers the weight of the old URL to the new URL, this will not affect the ranking of websites because of changes in the website.

If a website has registered multiple domain names, you must use 301 redirection to enable users accessing these domain names to automatically jump to one of the primary domain names. This is done to avoid a large amount of copying content, and is punished by the search engine. Because in the search engine's view, each domain name is an independent site. If multiple domain names direct to the same site, they will be considered as the site is the same, and the content will be copied, but the content will not be included in the sandbox, then, K is used directly.

301 redirection is required to normalize the website.

Suppose there are the following urls:

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

Http://admin10000.com

Http://admin10000.com/index.html

All do 301 redirection to the http://www.admin10000.com (the selected canonicalized URL), the search engine knows that the http://www.admin10000.com is a canonicalized URL, and will transfer the URL weights listed above to the canonicalized URL.

At present, Google will pass a majority of the weights, but not a weight. Baidu will transfer ownership. Google needs 1 ~ to identify, respond to, and complete Weight Transfer for 301 ~ 3 months. Baidu's 301 processing is conservative, and the new and old URLs will exist in the database for a long time.

Iii. Apache server 301 redirection

If the website uses a LAMP (Linux + Apache + MySQL + PHP) host, you can use Apache mod_rewrite to rewrite or redirect the URL. The following steps are required:

1. Make sure that the mod_rewrite function is enabled.

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

Continue searching for "AllowOverride None" and change it to "AllowOverride All ";

Restart Apache.

2. Place A. htaccess file in the root directory of the website where you need URL redirection. The file name is. htaccess. It cannot be directly created in Windows. You can save it as a file in notepad.

3. Use a regular expression in. htaccess to redirect to the desired page. Example:

Redirect 301 of top-level domain names without www to domain names 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]
Iv. How to Set 301 redirection on the IIS server

Example: Redirect admindomain.com to www.admindomain.com

1. Create a new site with a directory such as d: \ site. This site is mainly used for redirection. The directory can be empty without any files. Then bind the domain name admin).com to jump to the site,

2. Select the site we just created in IIS, right-click the site, properties, home directory, and select redirect, enter another website address bound to the domain name www.admindomain.com (the website contains website content ). The entered address is: http://www.admin10000.com $ S $ Q, and note that the following two options are selected: "permanent redirect options for resources" and "exact URL entered above. For example:

For the $ S $ Q character, here is an explanation:

$ S transmits the suffix of the requested URL to the new URL. The suffix is the part reserved in the initial URL after it is replaced by a redirected URL.

If the "entered accurate URL" option is not selected, the name of the target URL in the result will have the name of the requested file (as the folder name) and the file name itself.

$ Q: Pass the parameters (such as querystring) in the initial URL to the new URL, including the question mark (?).

If the $ S $ Q character is not added, 301 of the inner page will jump to the homepage. The purpose of adding the $ S $ Q character is that the inner page can also jump to the corresponding inner page of the new domain name accurately.

Okay, so that the 301 permanent redirect setting is completed. It is best to test whether the 301 redirection is successful after the setting. Webmaster tools HTTP status tool (http://tool.chinaz.com/pagestatus/) can be found, if the returned status is 301 it means you have succeeded.

5. Use ISAPI_Rewrite to implement IIS 301 redirection

ISAPI_Rewrite is a third-party URL rewriting component for IIS. It is based on regular expressions. Similar to the Apache mod_rewrite function, it not only implements URL rewriting, but also implements 301 redirection.

The ISAPI_Rewrite component has a free version (Lite) and a commercial version (Full). The free version only supports global httpd. conf configuration, you cannot set each site separately, and the commercial version allows each site to customize URL rewriting rules, as long as httpd. the ini can take effect in the root directory of the site.

Use ISAPI_Rewrite 2.x or the latest version 3.0 (which is compatible with the mod_rewrite Syntax of Apache). Earlier versions of 1.x do not support 301 redirection.

The following is an example:

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

# ISAPI_Rewrite 2.x [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteCond Host: ^ admin10000 \. com $ RewriteRule (. *) http://www.admin10000.com $1 [I, RP]
# ISAPI_Rewrite version 3.0 [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteCond % {HTTP: Host} ^ admin10000 \. com $ RewriteRule (. *) http://www.admin10000.com $1 [NC, R = 301]

2. 301 redirection between different domain names

# ISAPI_Rewrite 2.x [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteCond Host ^ www \. test10000 \. com $ RewriteRule (. *) http://www.admin10000.com $1 [I, RP]
# ISAPI_Rewrite 3.0 [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteCond % {HTTP: Host} ^ www \. test10000 \. com $ RewriteRule (. *) http://www.admin10000.com $1 [NC, R = 301]

3. redirect page 301 to another page

# ISAPI_Rewrite 2.x [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html $/newpage.html [I, O, RP, L]
# ISAPI_Rewrite 3.0 [ISAPI_Rewrite] #3600 = 1 hourCacheClockRate 3600 RepeatLimit 32 RewriteRule ^/oldpage.html $/newpage.html [NC, L, R = 301, O]
6. Implement 301 redirection in the webpage background program

If the page is ASP/PHP/JSP/ASP. NET, you can perform 301 redirection in the background code.

However, I personally do not recommend this because 301 redirection on the server starts to jump before your page is executed, which is highly efficient. In code 301, It is troublesome to add code to the header of each page.

Example:

1. 301 redirection in PHP

<?  Header("HTTP/1.1 301 Moved Permanently");  Header("Location: http://www.admin10000.com");?>

2. 301 redirection under ASP

<%@ Language=VBScript %><%  Response.Status = "301 Moved Permanently"  Response.AddHeader "Location", "http://www.admin10000.com"%>

3. 301 redirection under ASP. NET

<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 redirection under JSP

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

Tip: If the returned header contains only Location, but the status code is not explicitly mentioned, it means a 302 temporary redirection. Please remember. For example, the following are all 302 redirection:

302 redirection in PHP

<?   php header("Location: http://www.admin10000.com");?>  

302 redirection 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 redirection under JSP

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

Summary:301 redirection is the most user-friendly Method for search engines. Among many redirection technologies, 301 permanent redirection is the most secure and ideal solution. Whether the URL is permanently changed or URL normalization in multiple formats, 301 redirection is required.

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.