Can Apache serve a default file instead of a 404?

心已入冬 提交于 2019-12-13 03:45:49

问题


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 file - instead of a 404? If so, how?


回答1:


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.




回答2:


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




回答3:


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.



来源:https://stackoverflow.com/questions/1674603/can-apache-serve-a-default-file-instead-of-a-404

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!