Apache – Case-Insensitive mod_rewrite Redirect to Same URL

apache-2.2mod-rewrite

I'm using a case-sensitive web application to serve a few URLs that will be printed, so we expect UsErs to type them with inexact case. How do I tell mod_rewrite to redirect to the correct case URL as in [NC] without also redirecting on the case-exact URL and creating a loop?

Best Answer

This depends on a few things in your web application, but you could:

  1. Use mod_speling to force the correct capitalization of filenames and directories. This requires "real" filenames.
  2. Use RewriteMap to rewrite the url (as seen here):

In .htaccess:

RewriteEngine on
RewriteBase /
RewriteMap insensitive tolower:
RewriteRule ^[\/]*(.*)$ /${insensitive:$1} [R,L]