ad_728x90

參觀我的【 伊生活小舖】

2013年6月15日 星期六

正確設置404頁面及其他.505,500....

正確設置404頁面

404頁面的設置是否正確直接關係到網站粘性,而現在很多網站的錯誤頁面返回碼都是200和302,只要蜘蛛爬行錯誤頁面不是404,那麼你的404頁

面設置就是錯誤的了,這裡跟大家介紹如何正確設置404頁面。


怎麼正確設置404頁面?很多人看到這個話題可能覺得下文不屑一顧,其實你是否知道自己的404頁面有沒有設置正確呢?很多開源的cms系統和博客

系統都會帶有404頁面,你是不是覺得這樣已經ok了?不用設置了?這些想法是錯誤的,我們做優化的時候,應該測試404頁面時候生效,設置是否正

確等。下面我們詳細說明怎麼設置404頁面。


這先說一下怎麼樣的404頁面才是有效的404頁面。大家應該都知道搜索引擎是通過http狀態碼來識別網頁狀態的,那麼當蜘蛛檢索到一個錯誤鏈

接時,就需要返回404狀態碼來告訴搜索引擎,這個頁面是錯誤頁面,以後不用索取了。而如果返回200,則告訴搜索引擎這個頁面是正常頁面。

所以我們要查看網站錯誤頁面的返回碼是200還是404,而現在很多網站的404頁面返回碼是200而不是404.

  
那怎麼正確設置404頁面?



1.自己編寫一個404頁面,或者網上下載一個404頁面,把文件放置在網站根目錄。

2.設置方面,如果是購買的空間,那麼可以聯繫空間服務商幫

忙設置。如果是自主服務器,那麼要看自己安裝的是什麼服務器軟件,設置完後重啟服務器軟件,下面是三種比較流行的服務器軟件設置方法。


IIS:很簡單,在IIS中右鍵單擊要管理的網站,在自定義錯誤中設置404為相應的錯誤信息頁。


apache:在.htaccess 文件中加入代碼: ErrorDocument 404 /404.html


nginx:首先更改nginx.conf在http定義區域加入: fastcgi_intercept_errors on; 然後更改nginx.conf(或單獨網站配置文件,例如在nginx

-> sites-enabled下的站點配置文件)中在server 區域加入: error_page 404 /404.html(/前面切勿加=號,不然返回碼是200)

  
3.測試404頁面設置是否準確。你可以通過網上的一些404頁面測試工具進行測試,輸入一個不存在的url,然後測試其返回碼是否是404,如果是

404則正確,如果是200,那麼你的設置就是錯誤的了。


這裡有一些404頁面需要注意的地方。 /404.html前面不要放置主域名,不然很容易出現返回碼200;還有建議404頁面不要直接跳轉到首頁,直

接跳轉首頁的話,會導致很多錯誤url301指向首頁,有可能會出現首頁不收錄的狀況。


404頁面的正確設置可以幫助網站提高客戶粘性,所以希望大家對404頁面的設置重視起來,重點了解怎麼正確設置404頁面這方面知識。

及其他.......
If your website is on a server that allows you to have your own dot.com domain name you can create your own custom 404 error documents This is done by creating or modifying the .htaccess file in your root directory.

step 1 to creating a custom 404 error document is to create a .htaccess file
to do this open your text editor, notepad is best and add this line of text

ErrorDocument 404 /404.html

or you could use a full url
ErrorDocument 404 http://www.someserver.com/404.html

 Notepad

File Edit Search Help
ErrorDocument 404 /404.html







now save the file as ".htaccess"

important: note the double quotes around ".htaccess"
to view your .htaccess file, doubleclick on it and windows will ask what you want to open it with, select 'notepad' from the menu

step 2 to creating a custom 404 error document is to create the 404.html page, you can make your custom 404 error document anything you want, around the web you will find custom 404 error documents that simply have a link to the website homepage to custom 404 error pages that have search engines or even games on them

step 3 to creating a custom 404 error document is to upload the ".htaccess" file and the custom 404 error page (404.html) to your serverother common error codes

http error codes
Web server error messages have standard associated numbers
("http response codes"), for example the familiar 404 error message meaning "File not found" or the classic 403 error: Forbidden

The most common error messages are: 403, 404, and 500
lets look at one error at a time.

Error 403
this is most often encountered when the index.html of a folder is missing or the owner of the site has turned off permissions for either that page or its parent directory. If you get this error message and really want to see the page, you could try and contact the owner of the site and tell them what URL you were trying to access when you got the 403 error.
Permissions get changed as much by accident as on purpose, the author might appreciate knowing.

Error 404
This means that the URL as you've typed it doesn't exist.
Check the spelling and try again, but be aware that people take pages down all the time on the Internet. If you're pretty sure that the page is there, try and contact the owner of the site about the 404 error you got.

error 500
This means that there was a cgi script running that didn't work correctly, you can't fix it, and you can't move past it
you could try and contact the owner of the site.

create your own custom 403, 404 and 500 error documents then update your ".htaccess" file

heres an example ...

 Notepad

File Edit Search Help
ErrorDocument 403 /403.htmlErrorDocument 404 /404.htmlErrorDocument 500 /500.html




other http error codes:

100 Continue
101 Switching Protocols
200 OK
201 Created
202 Accepted
203 Non-Authoritative Information
204 No Content
205 Reset Content
206 Partial Content
300 Multiple Choices
301 Moved Permanently
302 Moved Temporarily
303 See Other
304 Not Modified
305 Use Proxy
400 Bad Request
401 Unauthorized (directory is protected by a password)
402 Payment Required
403 forbidden (all visitors are barred from looking at this file or directory)
404 file not found
405 Method Not Allowed
406 Not Acceptable
407 Proxy Authentication Required
408 Request Time-Out
409 Conflict
410 Gone
411 Length Required
412 Precondition Failed
413 Request Entity Too Large
414 Request-URI Too Large
415 Unsupported Media Type
500 internal server error (cgi script error)
501 Not Implemented
502 Bad Gateway
503 Service Unavailable
504 Gateway Time-Out
505 HTTP Version Not Supported

COMMENTS HAVE BEEN DISABLED FOR THIS POST [文章的評論已被禁用]

Ratings and Recommendations by outbrain