问题
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