How to set up 404 pages for your site (go)

Source: Internet
Author: User
Tags using git

A good website with a good 404 page is standard.

Why do you have 404 pages? How do I set up a 404 page?

Why 404 pages?

On the local, such as I open localhost/fuck.htm (the file does not exist), HTTP returns 404 Not Found, and the page is shown as follows:

The user experience is very poor there are wood! More importantly, if there is no 404 page, it will affect the SEO.

Why does that affect SEO?

When your site has some page address (path) changed. Or the content has been deleted, causing the original address to access this page, the prompt page does not exist. For example, your website revision, will also lead to a lot of original pages, access to the prompt page is deleted or does not exist. This time will produce a lot of dead links, when a website dead chain took more time, the search engine is very unfriendly, affecting the overall weight of your website, but also the user experience is very bad.

A 404 page is required. This page is the landing page for all dead links, and all pages that cannot be opened will jump to this 404 page. This page contains your main website column navigation. Users on this page can easily choose to continue to browse your site and other content. 404 after the page set up, through the Webmaster tool status code check, will return 404 status code. If the return status code is 200 description is set error (this result will cause the search engine may think that your site has a large number of duplicate content, so that the weight of the site is reduced), although for users to access the HTTP status code is "404" or "200" and no difference, But it is very important for search engines.

404 plainly is on the current page to do a return to the homepage or other pages of a link, this link on the one hand to tell the search engine we this page has been invalid please "Spider" again to climb home bar! So when the spider climbed to the dead link (404 pages) There will automatically run to the home page and index, that is, the emergence of 404 Not only for the search engine database to delete these dead links faster, but also to make the spider more diligent understanding of the new site, can be said to be double benefit.

Set 404 pages

The author summarizes two ways to set up 404 pages in APACHE. Of course, first you have to write a 404 page, after all, it is also an HTML page, the content can be brainstorming, for example, can write a small game Ah, show the site other content, or say 404 public welfare, and so on. Here I wrote a file named 404.htm, placed in the root directory of the local server (localhost/404.htm).

Method one ——. htaccess settings:

The first method is to make the relevant settings in the. htaccess file.

What is htaccess? As an overview, the htaccess file is a configuration file in the Apache server that is responsible for the Web page configuration under the relevant directory . Through the htaccess file, you can help us: page 301 redirect, custom 404 error page, change file extension, allow/block specific user or directory access, prohibit directory list, configure default document and other functions.

More about the htaccess file can refer to the end of the link or Google Baidu itself.

This file is not very strange, the wood has a file name, in fact, it is not surprising that using git, you must have seen. Git folder. But there is no such file under the local server? If you force a change of name from another file under Windows, you will be prompted to "type the file name" so we can use the command line.

After opening CMD,CD to the specified directory, you can create a. htaccess file with the following command:

echo.>.config

As stated earlier, the htaccess file is responsible for the configuration of the Web page under the relevant directory, so any folder under the server can have its own htaccess file. Here we put it under the root directory.

Open the file and copy the following:

ErrorDocument 404 /404.htm

Then open localhost/fuck.htm, the page content will become 404.htm content, return 404 status Code, the URL will not change.

(PS: So I have to take effect locally, but some articles point out that there are some changes in the Conf file, if not effective, you can refer to here)

Here are a few things to note:

    • One is not to omit the above ErrorDocument 404 /404.htm slash, if so 404 page will display the string "404.htm"
    • The second is the path can not use absolute address, for example, with "http://localhost/404.htm", so that the page open invalid link, will jump to "http://localhost/404.htm" address (change URL), return status code 200, this not only affects the inspection results of webmaster tools, but also affects the inclusion of SEO
    • Third, do not put 404 errors directly to the homepage of the site, which will affect the inclusion of the site. Some people may have doubts, what to do 404 page, 404 when directly to the site root file is not better, but also to the home guide, naive Ah, the search engine is not vegetarian, it will think you this is "cheating", so you do not have to see you.
    • If IE still does not jump over, it must be your 404 page content is too little, at least a B (byte) to let IE "surrender", think your 404 page is still sincere

Method two--vhosts settings:

Suppose you set a vhosts like a landlord. (If not, please refer to how to implement multi-domain configuration under wampserver)

The next is very simple, open the Vhosts file (such as my path \wamp\bin\apache\apache2.2.21\conf\extra\httpd-vhosts.conf), modified as follows:

<VirtualHost *:80>     DocumentRoot "c:\wamp\www"    ServerName localhost ErrorDocument 404 /404.htm</VirtualHost>

Note that the points are consistent with the htaccess setting.

Summarize

404 page is a mature site must have something, mainly has two functions, conducive to user experience and SEO. There are two ways to set up in Apache, htaccess and Vhosts, and some articles point out that using the latter as much as possible, the former is more resource-intensive. Please refer to the second section for points to be noted in the settings.

Read MORE:

    • What is the. htaccess?
    • tutorial on using PHP. htaccess files
    • 25 useful Apache '. htaccess ' tips
    • SEO Combat-what is the 404 page? What role does it have?
    • 404 page Baidu Encyclopedia

Http://www.cnblogs.com/zichi/p/5111869.html

How to set up 404 pages for your site (go)

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.