Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make this .htaccess rule case insensitive?

This is a rule in my .htaccess

# those CSV files are under the DOCROOT ... so let's hide 'em <FilesMatch "\.CSV$">  Order Allow,Deny  Deny from all </FilesMatch> 

I've noticed however that if there is a file with a lowercase or mixed case extension of CSV, it will be ignored by the rule and displayed.

How do I make this case insensitive?

I hope it doesn't come down to "\.(?:CSV|csv)$" (which I'm not sure would even work, and doesn't cover all bases)

Note: The files are under the docroot, and are uploaded automatically there by a 3rd party service, so I'd prefer to implement a rule my end instead of bothering them. Had I set this site up though, I'd go for above the docroot.

Thanks

like image 729
alex Avatar asked Mar 26 '10 01:03

alex


People also ask

Is http case insensitive?

By default, Web servers are expected to be case-sensitive. Although most HTTP servers support the HTTP specification that defines URLs as case-sensitive, some HTTP servers treat URLs as not case-sensitive.

What is $1 in Apache RewriteRule?

$1 represents the match from the first set of parentheses in the RewriteRule regex, not in the RewriteCond regex.


2 Answers

This page from the apache docs says that you can do it like this:

<FilesMatch \.(?i:csv)$> 
like image 175
Chad Birch Avatar answered Oct 10 '22 18:10

Chad Birch


Case insensitive:

<FilesMatch "(?i)\.(js|css|eot|ttf)$"> 
like image 23
Fox Avatar answered Oct 10 '22 16:10

Fox