Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question
up vote 2 down vote accepted

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]
share|improve this answer

First off, if you can use mod_speling that's easiest, but that requires actual files, not stuff hiding inside an application somehow.

Simply set a condition so the rewriterule doesn't happen if the request is capitalized properly, like so:

RewriteCond %{REQUEST_URI} !^/Your/File$
RewriteRule ^/your/file$ /Your/File [NC,R]
share|improve this answer

Mount a Samba share to /var/www and consider the Samba-share folder your wwwroot ;-))

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.