Paul Dessert
Paul Dessert

Reputation: 6389

rewriting URL to all lowercase

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

Upvotes: 0

Views: 658

Answers (2)

Mark Reed
Mark Reed

Reputation: 95315

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}

Upvotes: 1

daniel.auener
daniel.auener

Reputation: 1294

This article describes how to do it:

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

Upvotes: 2

Related Questions