May 21 2009

Apache 101 - Case insensitive URL's

Posted by Marcos Placona at 3:39 PM
3 comments
- Categories: VPS | Regular Expressions

This is only a quick apache tip for when you are using mod_rewrite.

I've been working on some rewriting lately, and noticed that when you use them, the pattern applied much match exactly, otherwise you will either get error, or your pattern will never find a match.

Obviously you have a few options when writing your rewrite rules to make it case insensitive, but that means you will have to use it on every single rule.

In my case, I simply want everything to come though as lower case, so even if you hit any of my pages with an upper case URL, it will automatically be rewritten to the same thing, but in lower case, and return 301, so the search engines know the page was permanently moved.

This is how I do it:

<code>#Make URL's lower case
  RewriteEngine On
  RewriteMap  lc int:tolower
  RewriteCond %{REQUEST_URI} [A-Z]
  RewriteRule (.*) ${lc:$1} [R=301,L]</code>

The RewriteMap directive needs to be placed on your httpd.conf or VHOST, as it won'#t work on directory level or .htaccess. Everything else can go on your directory or .htaccess.

Possibly Related Links:



Comments

johnb

johnb wrote on 05/22/09 12:12 PM

the -NC option on your rule should make it case insensitive
Neil Middleton

Neil Middleton wrote on 05/22/09 12:20 PM

And the reason for wanting to do this is?
johnb

johnb wrote on 05/22/09 12:41 PM

ah, I think I missed the point of your posting.
I'll shutup

Write your comment



(it will not be displayed)



Leave this field empty:







Related URLs

Subscribe

Categories

Search Archives

Monthly Archives