0

I have this rewrite rule in my .htaccess

RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /$1.php/$2 [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/$1_$2.php

How can I modify this to change everything in my URL to lowercase?

i.e. This:

www.mysite.com/ThisURL/SHOULD/be_all_lowercse

Should be

www.mysite.com/thisurl/should/be_all_lowercase
Paul Dessert
  • 6,363
  • 8
  • 47
  • 74
  • possible duplicate of [Convert to lowercase in a mod_rewrite rule](http://stackoverflow.com/questions/2923658/convert-to-lowercase-in-a-mod-rewrite-rule) – Marc B May 05 '12 at 05:06

2 Answers2

2

This article describes how to do it:

RewriteEngine On
RewriteMap  lc int:tolower
RewriteCond %{REQUEST_URI} [A-Z]
RewriteRule (.*) ${lc:$1} [R=301,L]
daniel.auener
  • 1,276
  • 2
  • 12
  • 17
1

Define a RewriteMap of type int (internal) referencing the tolower function, and call it where you want to do the lowercasing:

RewriteMap  lc int:tolower
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^/.]+)/?(.*)$ /${lc:$1}.php/${lc:$2} [QSA,L]
RewriteRule ^api/([a-z]+)/([a-z]+) /api/${lc:$1}_${lc:$2}.php}
Mark Reed
  • 91,912
  • 16
  • 138
  • 175