首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > Ruby Rails >

404 异常 Custom error pages using .htaccess

2013-04-21 
404 错误 Custom error pages using .htaccessOnce its done, login to your webspace with your FTP cli

404 错误 Custom error pages using .htaccess

Once it's done, login to your webspace with your FTP client, and create a new folder called "errordocs". Upload the file "error404.htm" to this directory. Upload "htaccess.txt" to the root of your webspace and rename it to ".htaccess" ?3 there's no .txt at the end, no name in front, just ".htaccess". If the file seems to vanish don't worry, some FTP clients don't display it ?3 the file's still there.

?

Trying it out

Now you need to see if it works. Type the URL of your website in your browser and add a random file name at the end. Something like "http://www.yoursite.com/dgsgdgsdgdsgg.htm".

?

If everything has worked properly, you should now be seeing your custom error message. If not, then it's possible your web host doesn't allow you to have your own .htaccess files. You may want to contact them and ask.

?

If it worked then you can now make a proper 404 page. You can have your own images, text, in fact anything else you can have in a normal web page. The best 404 pages have the site logo and a few simple lines explaining what's happened. If you have a site search, you could put that on it too in order to help visitors find what they're looking for.

?

Taking it further

There's several other error documents that you might wish to customise.

?

400 - Bad request
401 - Authorization Required
403 - Forbidden directory
404 - Page not found
500 - Internal Server Error

?

For each one you want to use, simply add a line to your .htaccess file and create the corresponding page.

<Files .htaccess>order allow,denydeny from all</Files>ErrorDocument 403 http://www.youdomain.com/error403.htmErrorDocument 404 /error404.htmErrorDocument 500 /error405.htm

?

?from: http://www.totallyphp.co.uk/custom-error-pages-using-htaccess

?

热点排行