-1

Problem:

   http://<server>/home/APPLE.html  
    http://<server>/hoME/APPLE.html
    http://<server>/HOME/aPPLE.html
    http://<server>/hoME/aPPLE.html

All the above should pick this

    http://<server>/home/apple.html

I implemented 2 solutions and both are working fine. Not sure which one is better(performance). Please Suggest..Also Directive - CheckCaseOnly on never worked

Option 1:

a)Enable:mod_speling In /etc/sysconfig/apache2 - APACHE_MODULES="rewrite speling apparmor......"

b) Add directive - CheckSpelling on (Either in .htaccess or add in httpd.conf) In httpd.conf

<Directory srv/www/htdcos/home>
Order allow,deny
CheckSpelling on
Allow from all
</Directory>

or

In .htaccess inside /srv/www/htdcos/home(your content folder)

 CheckSpelling on

Option 2:

a) Enable: mod_rewrite

b) Write the rule vhost(you can not write RewriteMap in directory. check apache docs )

<VirtualHost _default_:80>

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
</IfModule>

</VirtualHost>

<VirtualHost _default_:80>

<IfModule mod_rewrite.c>
Options +FollowSymLinks
RewriteEngine on
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
</IfModule>

</VirtualHost>

This changes the entire request uri into lowercase. I want this to happen for specific folder, but RewriteMap doesn't work in .htaccess. I am novice in regex and Rewrite. I need a RewriteCond which checks only /css//. can any body help

sysadmin1138
  • 133,124
  • 18
  • 176
  • 300
  • 1
    Since you say you only want this to happen for content under your `/css/` directory, it's probably worth mentioning that the most performant solution is to avoid the problem entirely, and fix the code to only refer to stylesheets by their lower-case filenames. – nickgrim Nov 01 '12 at 08:11
  • URLs are case sensitive, period. If you're running into this "problem", it's your development process you need to fix. – Michael Hampton Jan 08 '13 at 01:22

1 Answers1

1

The mod_rewrite solution doesn't make Apache case insensitive. It just makes sure that if the request is uppercase or mixed-case it will match resources which are lowercase. It doesn't address the situation in which the resource you want to serve is uppercase or mixed-case and the request doesn't properly match. It is not possible to make Apache case insensitive using mod_rewrite. (reference)

If you are sure that all the resources you ever serve will be lower case than this may meet your needs, but it is not case insensitive. Another potential issue is that the rewrite rule doesn't actually validate that the resource exists so, you may end up returning a 301 permanent redirect to a resource which doesn't exist. The impact to you may be minimal depending on how many case errors you get. The server will receive the second bad request and return a 404 which means increased load. No matter the impact to you returning a permanent redirect with a url that doesn't exist is bad form.

The mod_speling solution is actually case insensitive and will not return a redirect for a non-existent resource. There is some overhead since a directory scan needs to be performed by mod_speling to validate url against the target. If you are only concerned about case than use the CheckCaseOnly on directive to limit the checks performed by the module and thus the overhead.

TimS
  • 2,166
  • 13
  • 8