I recently switched from IIS to Apache and unfortionately some of my links have capitalization issues. I have seen quite a few people talking about how to rewrite urls to be all lowercase or all uppercase but I need something to just make Apache case insensitive. Is this doable with .htaccess?
-
Have you tried [this method](http://keystoneit.wordpress.com/2007/02/19/making-apache-case-insensitive/)? I don't think this can be done with `.htaccess`; this wouldn't fit the purpose of this file, but I may be wrong. – Peuczynski Jun 20 '13 at 21:16
2 Answers
add
CheckSpelling on
to your .htaccess
file
of course after enabling the RewriteEngine
so the final code will be
RewriteEngine on
CheckSpelling on
I guess it is the best and safest way.
dont forget to change
AllowOverride none
to
AllowOverride All
inside your httpd.conf
file, to allow .htaccess files to work correctly.
-
6I just get a 500 Internal Server Error on every page whenever I add `CheckSpelling on` – Michael Yaworski Feb 03 '14 at 08:59
-
It is working like a charm for me. try to remove everything else inside the .htaccess file other than RewriteEngine On CheckSpelling On and make sure you AllowOverride All inside you httpd.conf file – iEmad Feb 03 '14 at 15:58
-
1I've removed everything else. The only thing I haven't done is the httpd.conf file because I don't know how to access that. I'm on shared hosting with dreamhost. Is there a way to access that file, or do I have to find another way? – Michael Yaworski Feb 03 '14 at 19:18
-
Well then, try to contact them and see if they allow using .htaccess or not and ask if they have the mod_rewrite loaded or not – iEmad Feb 03 '14 at 23:43
-
They do allow .htaccess because I'm using it for other things. Thanks for replying. – Michael Yaworski Feb 03 '14 at 23:48
-
3For anyone else seeing this, you need the mod_speling module enabled as well. – Eirik H May 09 '15 at 06:40
-
For me it gave ' Invalid command 'CheckSpelling', perhaps misspelled or defined by a module not included in the server configuration ' – Tarlan Mammadzada Oct 10 '16 at 18:57
If CheckSpelling
isn't working for you and you're using PHP, you can add a PHP redirect in your 404 page to redirect to the lowercase version of the URL. To start, if you haven't already done so, add the following code to your .htaccess file (you can call the file something else than 404.php if you want, but it has to be a PHP file):
ErrorDocument 404 /404.php
Then add the following code at the beginning of 404.php (if you're using HTTPS, change http://
to https://
at the second line):
if(preg_match("/[A-Z]/", $_SERVER["REQUEST_URI"])){
header("location:http://" . $_SERVER["HTTP_HOST"] . strtolower($_SERVER["REQUEST_URI"]));
exit();
}
This code uses a simple regex to check if the requested URI contains uppercase letters, and if it does, it redirects to the same page but with lowercase letters.

- 8,409
- 22
- 75
- 99