Can Apache serve a default file instead of a 404?

2019-08-17 05:42发布

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?

3条回答
男人必须洒脱
2楼-- · 2019-08-17 06:16

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

查看更多
贼婆χ
3楼-- · 2019-08-17 06:17

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.

查看更多
forever°为你锁心
4楼-- · 2019-08-17 06:25

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.

查看更多
登录 后发表回答