简体   繁体   中英

Why does my website redirects when going to a URL of a file that doesn't exist, even if I don't have .htaccess redirecting?

I've been working on this for days...

When I go to the URL of a.jpg that doesn't exist, my website redirects me to a close file (1 character difference apparently). For example: 1234.jpg will redirect to 12345.jpg if 12345.jpg exists but 1234.jpg doesn't exist.

This website is not on Wordpress or other similar platforms. I took an existing code and developped on it. I have access to all the files and directories through Filezilla. I searched the .htaccess, but none of them had redirect lines. I tried to delete the .htaccess too, but same problem.

I was thinking, if we can't find the source of the issue, maybe some of you know how to code something that locally prevent any redirection from happening?

Thanks a lot for your help!

This sounds like you have mod_speling (one l ) enabled in the server config.

mod_speling scans the directory when requesting a file that does not exist. If there is "close match" (eg. 1 character difference) then it will issue a 301 redirect to that file. (Although if there are more than 1 file that is a "close match" then a list of available files will be presented to the user!)

You can disable this behaviour in .htaccess with the following:

CheckSpelling Off

This option is disabled by default, so it would need to have been explicitly enabled elsewhere in the server config. (If you have access, not enabling it in the first place would be preferable.)

Note that since a 301 (permanent) redirect was issued then you will need to clear your browser (and any intermediary) caches before testing.

Aside: The CheckCaseOnly directive (part of mod_speling) is more commonly used to restrict spelling corrections to case only, ie. to enable case-insensitive URLs.

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