Using NC in a .htaccess file not working

I am trying to create an .htaccess file that ignores the case sensitivity of my files. I have the following so far:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.html -f 
RewriteRule ^(.*)$ $1.html

This works when I type the file name exactly. For example, one of my files is About.html. When I type in www.domain.com/About, it goes to the right place, but when I type in www.domain.com/about, it does not.

I have seen posts about people using [NC], but I cannot get that to work either. I have also tried putting

CaseInsensitive On

But that seems to break everything (couldn't even load the home page), so I took that bit out. Does anyone have any idea on how to accomplish this?

Answers


Case insensitivity does not work like that, it activates case insensitivity for the regular expression matching, not the files.

For example :

RewriteRule ^somefile.php$ /index.php
RewriteRule ^somefile.php$ /index2.php [NC]

if someone try to access http://domain.com/SomeFile.php, it will not match the first line but the second line will, this will redirect him to index2.php (and not index.php). But if you the index2.php file is named instead INDEX2.php, the redirection will throw a 404 not found error.

What you are looking for is using RewriteMap. you need to put this in you server configuration file :

RewriteMap lc int:tolower 

Restart apache, and use a rule in your htacces like this :

RewriteRule ^(.*)$ /${lc:$1} 

This will turn any request to lower case, your files then must be all lowercased.

More informations about RewriteMap => see documentation


Need Your Help

How to better rasterize a plot without blurring the labels in matplotlib?

python matplotlib transparency eps

I usually use ax.set_rasterized(True) to rasterize the figure so that it could handle transparency when saved as in eps format, but the rasterization also blurs the axis labels and ticklabels, so is

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.