CakePHP and apache mod_speling

Can CakePHP and apache mod_speling co-exist in the same website?

A customer’s site runs on CakePHP. In webroot they have an unconnected, static folder of files that can be download directly bypassing Cake with a URLs like…

http://test.com/downloads/myfile1.txt
http://test.com/downloads/myfile2.txt
etc

These URLs are accessed by external software. This all worked fine.

However they have now replaced the old static files with new ones but have changed the case so myfile1.txt has become Myfile1.txt

Unfortunately the external software is still requesting the old filenames. CakePHP shows this as a 404 error.

This affects many thousands of files, they are trying to avoid renaming them all. It was suggested that the mod_speling apache module be added to sort this.

I have added and configured it but with no success. When a file like myfile1.txt (which no longer exists) is requested it is still grabbed by Cake as a 404.

I’ve tested mod_speling on an non-CakePHP site on the same server and it works fine, so we’ve got it installed and running properly. It seems Apache does a 301 redirect from the requested file Myfile1.txt abnd serves myfile1.txt

So my conclusion is that having mod_speling redirecting and CakePHP working in basically the same way these two cannot run together on the same site.

Does anyone know for sure? Am I trying to do the impossible or is it likely I’ve just made an error somewhere?

Your web server is probably using mod_rewrite to redirect requests to CakePHP where the file doesn’t exist, so it’s probably a conflict between mod_rewrite and mod_speling, rather than CakePHP and mod_speling.

There are a few articles around the place that seem to suggest the two can’t run together, without looking for specific edge cases.

This article is a bit inconclusive, but suggests a couple of mod_rewrite options to use.
http://stackoverflow.com/questions/1978737/mod-speling-mod-rewrite-to-work-together

This article suggests that the two are not compatible

You could try altering the RewriteCond %{REQUEST_FILENAME} !-f rule, and append [NC] to make is case insensitive. The doco seems to suggest that these flags are for RewriteRule only, but this article [http://stackoverflow.com/questions/22359280/trying-to-make-rewritecond-case-insensitive-htaccess] seems to suggest that it might work for RewriteCond. That article is checking for the existence of a file, not the absence, so that may be different.

The horrible work around would be to write a Downloads controller that gets invoked when the file can not be found, and does it’s own case insensitive search on the directory, serving back the file with the requested case.

Thanks for that, some great stuff to look into. I’ll report back with what we end up doing.

Cheers

Paul