301 redirect complete analysis

When optimizing a website, 301 redirect is an indispensable optimization for webmasters, and 301 redirect is mainly used to move content from one location to another. In fact, it is very simple to understand. For example, I have some content on http://www.abc.com/a.html, and then I want to refactor the website, so I want to move the content on this page to http http://www.abc.com/b.html on. Therefore, I can implement a 301 redirect to transfer all the indicators of this page to another page.

Some people may ask, why do you have to do 301 redirects for refactored websites? First of all, before doing 301 redirects, we must understand that redirects are not only important for users, but also for search engines. By implementing a 301 redirect, users or search engines can access the old version of the page instead of the 404 error page, but successfully access the new version of the page. It can also let the search engine know when you moved the content, so it will need to be reconstructed. The website does a 301 redirect.

Why are we talking about the 301 redirect problem today? The reason why we talked about this problem is also because I found various 301 redirect problems when analyzing and diagnosing the corporate website: for example, the old version of the page was useless after the corporate website was reconstructed. Redirecting to the new version caused a large number of 404 error pages on the reconstructed website, and the website also lost weight and lowered its weight because of these 404 pages.

In addition, when setting the 301 redirect, there was a setting error or not knowing how to set it. The author found that the webmasters of many companies did not know enough about 301 redirects and made mistakes. Let's do some sorting out for this problem, hoping to help small and medium-sized enterprise webmasters set 301 redirects correctly and effectively.

 1. The role of 301 redirect

301 redirects have many functions. Usually, when webmasters do 301 redirects, one is to standardize the URL and concentrate the weight to prevent the weight from being scattered, and the other is to redesign the website to transfer all the indicators of the old version of the page to the new one. Version on the page. The implementation of 301 redirects can do this, and it is also very powerful. It is also recommended that webmasters of small and medium-sized enterprises make effective use of the effects of 301 redirects on websites.

 2. Under what circumstances must do 301 redirect

The following five situations require 301 redirection. Of course, if these five situations do not occur, you can choose not to do it. The following is a detailed introduction.

①: The old content of the website has expired and been deleted

Some content of the website is out of date, so it should be deleted. If you want to keep it, you can use a 301 redirect.

②: The website has some invalid URLs with links and traffic

If you find that these invalid URLs still have traffic weight, you can regenerate the page through a 301 redirect.

③: The website has replaced the hosting company

If the website is replaced by a hosting company, there is no need to do a 301 redirect without affecting the user's search for any URL of the website content.

④: Website replacement procedure

The website undergoes a major revision, and the website program needs to be replaced. At this time, many URLs will be affected, which can be solved by 301 redirects.

⑤: The website implements URL standardization

The default URL of the website:

1 、 abc.com

2、www.abc.com

3、abc.com/index.html

4、www.abc.com/index.html

In order to normalize the URL and not disperse the weight, usually only one standard URL appears, and we can achieve it through a 301 redirect. For example: the URL of my website only shows the URL of http://www.abc.com/, I can redirect the other three URLs to this URL through 301, so that the weight will not be dispersed since then, maybe with index. 301 redirection of html suffix URL is prone to infinite loop. In order to avoid such a situation, there is a solution, which will be explained in detail below.

⑥: The website changes the URL of the existing content due to various reasons

It is possible that the corporate website has changed the URL of the existing content due to various reasons. This situation cannot be predicted by the webmaster. If this happens and the URL is changed, it is recommended to use a 301 redirect. Solve, try to avoid the appearance of dead links.

Summarizing the above needs to be noted: not all situations require 301 redirects; however, any URL changes require 301 redirects. The reason is simple, in order to avoid 404 error pages that shouldn't happen.

  Three, do 301 redirect matters needing attention

After the 301 redirect is implemented, the old version page jumps to the new version page, or the URL is standardized or other, most webmasters will not notice whether the 301 HTTP status is returned successfully. At this moment, the 301 redirect of some websites may not deliver the status or the 404 error status code may appear, which may easily cause the 301 redirect to fail to achieve the effect under any circumstances. The author believes that for correct and effective 301 redirection, some details still need to be paid attention to.

For example: 404 error (page not found) or 200 OK (page successfully loaded); 301 (return 301 status code success)

Correct HTTP status code:

Wrong HTTP status code:

To sum up the above needs to pay attention: if you encounter this situation, it is also a problem that is valued, so to avoid such problems, if the webmaster does a 301 permanent redirection, be sure to make sure that the HTTP status is returning 301, if the HTTP status code It is not the returned 301 status code but 200 or 404 or other status codes. Then the 301 redirection operation should not be successful. It is recommended that the webmaster check the problem and solve it.

4. Will the weights overlap after 301 permanent redirection?

Will the weights be superimposed after 301 permanent redirection? Many webmasters are considering this issue, and some webmasters want to use this approach to speculate. The weights can be superimposed after the 301 permanent redirection, but the weights will not be added. So, what kind of websites do 301 redirect weights can be superimposed, what kind of websites do 301 redirect weights can not be superimposed? The following is a detailed explanation.

①: The weights can be superimposed for two identical websites to do 301 redirects, but not all the weights are transferred, and it depends on the site compliance rules. Generally speaking, a part of the weights will be lost when the weights are transferred again.

②: It is not possible to add weights for two different websites with 301 redirects. Why? If the two websites are not the same at all, the weights will not be transferred, and Baidu is not willing to do so, so the two do not The same website cannot pass weights and overlay weights.

 Five, the difference between 301 redirect and 302 redirect

There are actually many redirection methods, but different methods will have different results, and the differences are also very big. Currently, according to the HTTP status code returned by the WEB server to the browser, redirection is mainly divided into 301 permanent redirection and 302 temporary redirection. The two types of redirection are done according to different situations. The two types of redirection are detailed below Explain in detail.

①: 301 permanent redirection

First, 301 permanent redirection. This status code tells users, search engines, and browsers that the resource has been permanently moved to another location (the old version page is permanently redirected to the new version page), and there is no plan to restore it. 301 permanent redirect is most suitable for directory transfer, 301 redirect is recommended!

②: 302 temporary redirect

Then, 302 is temporarily redirected. This status code tells users, search engines, and browsers that the resource has been temporarily moved to another location (the old version of the page is temporarily redirected to the new version of the page), this movement will not be regarded as permanent, and will be restored to the original Location, but in some cases 302 redirects are suitable.

302 redirection has certain benefits for mobile station optimization. Baidu's official suggestion is: for example, reduce content dead links. If there is no content, it is best to specify through HTTP status codes, such as 404, 403, etc.; if content dead links, you want to redirect To the homepage, it is best to jump through 302 instead of javascript. At this point, it can be found that the 302 redirection is beneficial to the optimization of the mobile station.

Note: Both forms of redirection will send users and search engines to a new location (page), but search engines treat these two HTTP status codes differently. When the search engine sees the 301 status code, it will determine that the old version of the page will permanently transfer the weight or any other indicators to the new page. When a search engine sees the 302 HTTP status code, it will assume that it should not transfer the historical links and weights of the old page to the new page, meaning that it will be transferred back after the transfer. In addition, if you do a 301 permanent redirect, it will cause search engines to delete old pages from the index (Baidu, Google) and replace them with new ones.

6. How to avoid looping when 301 redirects the index file on the homepage permanently

Webmasters who are doing optimization should know that most of the homepage URLs of websites are in the form of http://www.abc.com/index.html, but generally they are entered as http://www.admin5.cn /Visit the homepage. At this time, two versions of the URL appeared on the homepage, and the impact on the website was to decentralize the link weight. Some webmasters may think of URL standardization. Yes, that's right, a standard URL expression form can be realized through URL standardization.

When most webmasters see this situation, they will redirect http://www.abc.com/index.html to http://www.admin5.cn/ through 301 permanent redirection, and then use 301 permanent redirection. Targeted repair URL. However, if the webmaster does not implement the 301 redirection correctly, the problem of 301 redirection is usually enlarged, such as an infinite loop.

Default document redirection solution:

①: Copy the content of index.php to another file, such as a.php file.

②: Create an Apache DirectoryIndex command for the document directory, set the quality target to a.php, do not set this command at the server-wide level; otherwise, it may cause other folders that still need to use index.php as a directory index The problem.

③: Put in the .htdaccess file in the document root directory: DirectoryIndex a.php Or, if you do not use separate context files in each directory, you can put the following content in .htdaccess: DirectoryIndex a.php

④: Clear the content in the original index.php file and insert the following code:

To summarize the above, note: this setting makes index.php no longer a directory index file, which is the default file name. It will force a.php to be read when the user enters the canonical URL http://www.abc.com/, so any request from the old link to index.php now undergoes a 301 redirect and avoids an infinite loop.

 Seven, how to implement 301 redirect

①: virtual host

Linux virtual host setting 301 jump method:

Create a new text file locally, it is best to use a professional editor software such as EditPlus to paste the code into

RewriteEngine On

RewriteCond %{HTTP_HOST} !^www.abc.com$ [NC]

RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

Note: The above rule is to redirect all access domain names of the site to www.abc.com (please modify the domain name in the rule to your own domain name). If you only want to bind to a certain domain name on the site (such as: www.123) .com) Redirect to www.abc.com, the rules are as follows:

RewriteCond %{HTTP_HOST} ^www.123.com$ [NC]

RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

If there are multiple needs, such as abc.com jump to www.abc.com qwe.com jump to www.qwe.com, the rules are as follows:

RewriteEngine On

RewriteCond %{HTTP_HOST} ^abc.com$ [NC]

RewriteRule ^(.*)$ http://www.abc.com/$1 [R=301,L]

RewriteCond %{HTTP_HOST} ^qwe.com$ [NC]

RewriteRule ^(.*)$ http://www.qwe.com/$1 [R=301,L]

Add and modify according to your needs, then upload it to the server wwwroot directory and rename it to .htaccess

Win virtual host setting 301 jump method:

Manually set (not automatically generated)

1. Enter the host control panel, enter the ISAPI filter settings, and click the "Enable custom URL static support" button.

2. After enabling the pseudo-static function, enter the FTP file management and find \others\discuz\httpd.conf to modify the rules inside.

3. Sample code:

RewriteCond %{HTTP:Host} ^abc.com$

RewriteRule (.*) http://www.abc.com$1 [NC,R=301]

#The first item indicates the domain name to be redirected, and the second item indicates the domain name to be redirected to

#If there are many domain names to be redirected, you can change the first rule to

RewriteCond %{HTTP:Host} !^www.abc.com$

In this way, it means that domain names that are not www.abc.com will be redirected to www.abc.com #The second way to redirect multiple domain names is to copy multiple RewriteCond items first, and change the domain name except the last one Item, the remaining RewriteCond items must add a parameter [OR] at the end.

Note: Many virtual hosts now have their own 301 configuration, you can generate code information on the host control panel, and then follow the above prompts to perform 301 redirection.

②: window independent service

Win independent service 301 settings (win2003, win2008):

1. The IIS server implements 301 redirection

Open IIS, right click-properties-website-IP address to add a site, and then bind the host header, you can also bind more idle domain names. as the picture shows:

Open IIS, first create a new site, which corresponds to a directory E:\wwwroot\301web. Only two files are needed in this directory, one default.html and one 404.htm. Right-click on the webpage or directory you want to redirect; select "Redirect to URL"; enter the address of the target page in the dialog box; remember to select "Permanent redirection of resources"; of course, click "Apply" at the end ,carry out. As shown below:

Note: Both win2003 and win2008 use the IIS server, so the steps of 301 redirection are the same.

③: Linux independent server

Linux stand-alone server 301 settings (Red Hat Enterprise Edition, centos):

I use Red Hat Enterprise Edition, and I use a source-packaged Web environment. Then I entered the Linux server and found the main apache configuration file httpd.conf. There are multiple virtual hosts under my apache server. I found the virtual host I want to do 301 redirection, and then add the code (the code is complete) :

1. Enter the Linux server and find the Apache main configuration file of httpd.conf. The red box in the figure below is the complete location where I am, and the blue box is the content, which is the actual location of the command pwd, and ls queries the content of the current location.

Now that the main configuration file is found, we edit it through the command vi httpd.conf and add the following complete code at the end. To find the configured virtual host and add the code, don't add it randomly.

ServerName www.abc.com

ServerAdmin [email protected]

LogLevel warn

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

ServerName abc.com

ServerAdmin [email protected]

RewriteEngine on

RewriteRule ^(.*)$ http://www.abc.com$1 [R=301,L]

LogLevel warn

ErrorLog logs/dummy-host.example.com-error_log

CustomLog logs/dummy-host.example.com-access_log common

Note: The paths of Apache installed in different forms are different. There are source code packages, YUM and other installation methods. The two roads are different. It is recommended that novices contact the space provider and implement 301 redirection.

④: Bind/local DNS

If you have the authority to edit and modify local DNS records, you can solve this problem by adding only one record. If you don't have this permission, you can ask the website hosting service provider to set the DNS server accordingly.

⑤: DNS server settings

If you want to point blog.abc.com to www.abc.com, you only need to add an alias record in the DNS service, which can be written as: blog IN CNAME www.abc.com.

If you need to configure a large number of virtual domain names, you can write: * IN CNAME www.abc.com.

In this way, all unset records ending with abc.com can be redirected to www.abc.com.

  Written at the end:

The above is the 301 redirect organized by the author. In general, the website revision can pass all of the old version of the page to the new version of the page through a 301 redirect, and the other is to standardize the URL. In the implementation process, we should pay attention to why we need to do 301 redirection, method operation, correctness of operation, etc. In order to better set up 301 redirection, it is recommended to refer to the content organized above.

This article was originally edited by A5 Marketing SEO Diagnostic Service www.admin5.cn/seo/zhenduan/, please indicate the source for reprinting!

Guess you like

Origin blog.csdn.net/qq_36129701/article/details/104790260
301