简体   繁体   中英

404 errors being redirected to the homepage instead of custom 404 page

I have a site hosted on an Apache server. I have created some custom error pages and the following text at the top of my .htaccess file :

ErrorDocument 404 404.html

ErrorDocument 500 500.html

ErrorDocument 401 401.html

I have also tried,

ErrorDocument 404 /404.html

ErrorDocument 500 /500.html

ErrorDocument 401 /401.html

Both the htaccess file and the custom pages are in the root directory of the server. The problem is that when I enter a garbage url (where I would expect to see my custom 404 page) I'm simply being redirected to my index page.

Try if your server is properly set up to parse and process .htaccess files in the first place (ie, check if AllowOverride + AccessFileName directives are correct). For example, write some stuff in that you know will work and look if it actually gets executed (like a ridiculous rewrite rule). Also, look up your httpd log files for errors.

If it does get executed properly, the problem might be that your server is setup not to allow all kinds of overrides with .htaccess files. Your syntax however, is basically correct.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM