开发者

Can Apache serve a default file instead of a 404?

We have Apache serving a set of files from a particular directory. If a file requested in that directory does not exist, can I make Apache return a default开发者_Python百科 file - instead of a 404? If so, how?


This can be achieved making use of .htaccess.

Check this WebReference article on the topic.

Basically you only need a file name .htaccess in your directory which contains

ErrorDocument 404 /YourCustomErrorPage.html 

Of course any other file can be served too.


What kind of file? Is it a static file? With Apache you can set custom error pages.


Be careful returning non-404s for any random URI request. It may impact your Google rankings if they notice it and consider it part of a link farm or other such blackhat SEO technique.


If you want to return a file successfully instead of with a 404 status, you can use the FallbackResource directive instead of ErrorDocument.

FallbackResource /YourCustomDocument.html
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜