How to Do Error 404 automatic page Jump

Source: Internet
Author: User
Tags website server

Recently I found a more detailed and reasonable article. Some of them must think it is very important. The 404 page adjustment should not use Meta Refresh, which makes it easy for search engines to misjudge and deserves attention. Second, there is a point of view that do not jump to the home page, which will damage the weight of the Home Page. This article does not seem to have said so. In my opinion, the 404 page adjustment should not use Meta Refresh, do not skip to the homepage.

An HTTP 404 error indicates that the webpage to which the link points does not exist. It is impossible to completely avoid this situation during website construction. For example, we often need to adjust and revise the website so that the webpage will be deleted, renamed, or moved, although the webpage with the corresponding content still exists in the website, it cannot be accessed by using the original address. -- Of course, the first thing to consider for this kind of situation is to make 301 redirection for the original page address to minimize the effect on Seo. -Second, when someone else creates a link to a website, it may also become an invalid link due to spelling errors: The corresponding content page cannot be found on the website.

Simply put, these invalid links are automatically processed by the Web server: when the web server receives similar data requests, it returns a 404 status code, tell the other party that the requested resource does not exist. However, no matter Apache or IIS, the default 404 error page of the Web server is very simple, dull, and unfriendly to users, and users cannot find more clues about the corresponding information, when users see such pages, the most direct response is to close the browser window and exit, which causes a lot of losses to the website. After all, users are always the most important resources for websites. Losing users in this way means failure to some extent.

This is why many websites use a custom 404 error page. Through a well-defined 404 page, you can include corresponding introductions to the website, content links that users may be interested in, navigation links to the website content, and content search functions, it can effectively help visitors find the content they want to find or similar content, and improve the chance for users to browse more information on the website.

The custom 404 error page returns the "200" or "302" status code.

From a strict technical point of view, the website's policy to handle 404 errors is not a Seo task, but a matter of website availability (usability. -- Of course, if you look at Seo In a broad sense, improving website availability is also a basic Seo operation. -- If the custom 404 error page is improperly set, the SEO effect of the website will be greatly affected.

In the impression of many friends, as long as the custom 404 error page can be correctly displayed, as long as it can enter a webpage address that does not exist in the website, you can see the custom error information in the browser, it indicates that the settings are correct. I am ashamed to say that I am also a member of this kind of thinking. It technology reviews have been running for nearly a year. Recently, it was found that there were similar errors only when I checked the website after Google updated rankings: A correctly set 404 page should not only be correctly displayed, but also be able to correctly return the "404" error code instead of "200" or "302 ". Although there is no difference between the HTTP status code "404" and "200" for the accessed users, this is very important for search engines.

Why? Let's review the process of indexing and indexing web pages by a search engine: the search engine spider sends a request to the website server to read a webpage, after receiving the request, the website server returns an HTTP status code to respond to the request. The returned HTTP Status Code determines the next action of the search engine: you can include or delete the webpage from the index database.

Of course, there are many types of HTTP status codes, which correspond to different situations. The following is a brief introduction to the content of this article. For more details, see W3C specifications:
404: the requested webpage does not exist (the possibility of future validity of the link is not ruled out );
410: the requested webpage does not exist (permanent );
200: the server returns the webpage successfully.
302: Temporary URL redirection (redirection)
301: Permanent URL redirection

It should be noted that most search engines treat "404" as "410", such as Google. (See the description of Matt Cutts)
When a search engine returns a 404 status response when requesting a URL, it will know that the webpage no longer exists in the website and then delete it in the index database. -- of course, this deletion process may take a long time-when the search engine returns the "200" status, the URL is considered valid and returned to the index database.

Result of "404" status code returned on the 200 page

If the custom 404 error page of a website does not return the "404" status code when the URL is invalid and is replaced with "200", what will happen? Obviously, search engines will think that this "nonexistent" webpage exists in the website, which will lead to many problems and affect the final Seo effect of the website.
For example, the phenomenon of "duplicate content" is a taboo for many search engines. This is especially because the website cannot only have these two invalid links. After all, during website construction, no matter the internal or external links of the website, there will always be many mistakes, such as spelling errors, similar duplicate content will be more. In this way, for search engines, especially Google, it is not only difficult to obtain the desired website Trust Index, but also greatly reduces Google's evaluation of website quality.

404 errors caused by Meta Refresh on the 302 error page

The custom 404 error pages of many websites are usually displayed in the following format: first, an error message is displayed, and then the page is redirected to the homepage, webpage map, or other similar pages of the website through Meta Refresh. Depending on the specific implementation method, this type of 404 page may return a "200" status code or "302", but either way, from the SEO perspective, is not a proper choice.

We have already talked about the "200" status, so what will the search engine do when "404" is returned on the 302 Page? In theory, for the "302" error, the search engine considers that the webpage exists, but the address is changed temporarily and the page will be indexed, duplicate text similar to the "200" Status Code may also occur. Second, mainstream search engines, represented by Google, have increasingly strict requirements on the applicability of 302 redirection, this type of improper use of 302 redirection poses a great risk.

Therefore, try not to use this Meta Refresh method on the 404 error page. If you want to implement a similar function, that is, to jump to the homepage or other pages after displaying the error message for several (10) seconds, you can use Java Script to jump to the 404 error page. -- Java Script is useless and harmless to search engines.

Make sure that the custom 404 error page returns the "404" status code

After setting the custom 404 error page, make sure that the "404" status code is returned correctly.

The check method is also quite simple. Use the server header check tool provided by this site, or other similar tools such as this, enter a URL without a webpage in the website, and check the HTTP header return information, make sure that "404 Not Found" is returned ".

This article focuses on Apache + PhP websites. If it is win, the idea is similar. Custom 404 page, that is, when a user accesses a page that does not exist, the default server error page is not displayed, but a prompt page that is prepared in advance is displayed, the URL in the address bar of the user's browser is still the URL entered/accessed by the user. There are at least two advantages:

It makes users feel that this error is still under the control of the website. "This is part of the performance ".

Let the webmaster instantly know that there is such a 404 page.

Let's talk about several possibilities that generate 404

User-Agent (browser and search engine bots) will access fixed files, such as Maxthon/ghost files.

The user entered the URL incorrectly. For example, if someone previously visited the website's page/page1.html, and then re-accessed it using the record function in the browser's address bar, the backspace was accidentally treated as a carriage return, after realizing this, the/page1.htm page was directly accessed by pressing the Enter key because the hand was faster than the brain (with an L missing ).
A page is deleted, and other websites, such as forums and search engines, are still referencing this link.

For the first kind of situation, of course, the favicon.icoand robots.txt files are uploaded to the root directory, so there is no more to say about the creation method and writing rules. In the second case, we can differentiate it from the third case, that is, the webmaster is notified only when the third case occurs.
The following describes how to create a custom 404 page using Apache + PHP.

First, you can use Apache to process the case where the file does not exist. htaccess definition. There are a lot of articles introduced on the Internet. add errordocument 404/404 .php (/404. PHP is custom 404 page ).

Second, we need to deal with another more common 404, that is, 404 of the data that does not exist. For example, this blog system is database-driven. When a user accesses an article, the blog program queries the database based on the ID. If this article happens to be deleted, it should tell the user that the page does not exist, the same situation is also suitable for the prompt after the Forum is deleted. Currently, most blogs, forums, and other data-driven websites handle this problem by displaying only nonexistent prompts without sending 404 headers, or simply turning to/404. PHP page (the address bar of the browser becomes/404.php ). The disadvantage of this approach is that the search engine will see that the website has a lot of the same content (all do not exist prompt text), different pages with different URLs, or you can see that many websites are directed to the same page through 302, these may all be punished by search engines for being spam (many of the websites that have been punished always think they are innocent, but they are actually the result of small errors ). Because the server layer has been passed and the 404 definition of. htaccess no longer works, the PHP file for reading data should be processed as follows:
$ Id = $ _ Get ['id']; // obtain the index ID of the article or post.
// Query the database with $ ID
If (if there are no results)
// In the past, only the prompt "this post does not exist" was displayed. Now it is:
Request ('/404. php ');
@ Header ('HTTP/1.1 404 Not found ');
@ Header ('status: 404 Not found ');
This ensures that the content of 404. php is displayed, and the 404 header is sent, and the URL in the browser's address bar is still the original URL accessed by the user. From the perspective of human understanding, the header () Statement is usually placed on require (), but it will cause PHP to stop executing the following require function and put the header at the end to send the 404 header. It is recommended that users who write forums, blogs, and data-driven website programs use the above methods to process prompt information when data does not exist, so as to avoid misunderstanding with search engines. Please note that the post is from Seo In Jiangxi and Seo In Nanchang ,.
Finally, let's talk about the problem of notifying webmaster, that is, to distinguish the second and third cases that generate 404. Obviously, the difference between the two cases is that case 2 does not contain referer information, so the code that notifies webmaster should be like this:
If ($ _ server ['HTTP _ referer']! = '') // If a referer exists, it indicates the click from a page.
Mail (... send the 404 page $ _ server ['request _ url'] And Referer page $ _ server ['HTTP _ referer'] To the webmaster mailbox by email );
In this way, the webmaster should immediately contact $ _ server ['HTTP _ referer'] to modify the webmaster link after receiving the email. If $ _ server ['HTTP _ referer'] is a search engine, the 404 header is sent to the custom 404 page, and the search engine will delete the page the next time it updates the index. If you are not at ease, you can add a meta tag to the header of the/404. PHP page to reject all bots:
<Meta content = "noindex, nofollow" name = "Robots"/>
In this way, nothing is lost.
5 seconds later !!! Automatically jump to the site homepage!
<! Doctype HTML public "-// W3C // dtd html 4.01 // en" "">
<HTML> <Meta HTTP-EQUIV = "Content-Type" content = "text/html; charset = gb2312">
<Style type = "text/CSS">
Body {Font: 9pt/12pt}
H1 {Font: 12pt/15pt}
H2 {Font: 9pt/12pt}
A: link {color: Red}
A: visited {color: maroon}
# Goto {color: # ff0000; font-size: 30px; font-weight: bold}
<SCRIPT type = "text/JavaScript">
Function out (OBJ ){
VaR I = OBJ;
If (I = 0)
Document. Location. href = " ";
Document. getelementbyid ("Goto"). innerhtml = I;
I --;
SetTimeout ("Out (" + I + ")", 1000 );
</Head> <body onload = "Out (5);"> <Table width = 500 border = 0 cellspacing = 10> <tr> <TD>
<H1> This page cannot be found The page you are searching for may have been deleted, renamed, or temporarily unavailable.
<Div> <span id = "Goto"> </span> is transferred to the homepage in seconds, or you can click <a href = "http: //"> HTTP: // </a> </div>
<P> perform the following operations: </P>
<Li> make sure that the spelling and format of the website address displayed in the address bar of the browser are correct. </LI>
<Li> if you have reached the webpage by clicking the link, contact the website administrator to inform them that the URL format is incorrect.
<Li> click <a href = "javascript: history. Back (1)"> back </a> to try another link. </LI>
<H2> HTTP Error 404-the file or directory is not found. <Br> Internet Information Service (IIS) </H2>
<P> technical information (provided by technical support personnel) </P>
<Li> go to <a href = " Linkid = 8180 "> Microsoft Product Support Service </a> and search for titles including" HTTP "and" 404. </LI>
<Li> open "IIS Help" (which can be accessed in the IIS Manager (inetmgr ), search for topics titled "website Settings", "Common Management Tasks", and "custom error messages. </LI>
</TD> </tr> </table> </body>

This article is a reprinted article. If you think it is very good, you can record your blog so that you can check it later.


How to Do Error 404 automatic page Jump

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: 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.