Home > Back-end >  Why does my website redirects when going to a URL of a file that doesn't exist, even if I don&#
Why does my website redirects when going to a URL of a file that doesn't exist, even if I don&#

Time:12-08

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!

CodePudding user response:

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.

CodePudding user response:

MrWhite's comment matches very accurately my situation.

I searched in all files with Notepad the terms 'CheckSpelling', 'CheckCase' and 'mod_speling' but couldn't find any of them.

I added the line 'CheckSpelling Off' at the end of my .htaccess and... magic. Problem solved.

It would be great if I could find where the problem comes from but at least it's fixed. Thanks a lot, and thanks to the entire community as well. I'm impressed by how fast and how valuable were the given answers!

  • Related