Saturday, August 13, 2011

Apache's mod_rewrite and changing URL cases...

Suppose we want to use Apache's mod_rewrite RewriteMap: to

RewriteMap uppercase int:toupper
RewriteRule [a-z] %{uppercase:%{REQUEST_URI}} [L,R=301]
The list of internal functions are listed here:
Internal Function
MapType: int, MapSource: Internal Apache function
Here, the source is an internal Apache function. Currently you cannot create your own, but the following functions already exist:

Converts the key to all upper case.
Converts the key to all lower case.
Translates special characters in the key to hex-encodings.
Translates hex-encodings in the key back to special characters.

You can also use this approach to map static content to a list of servers:

Rewrite map file

##  map.txt -- rewriting map

static   www1|www2|www3|www4
dynamic  www5|www6
Configuration directives

RewriteMap servers rnd:/path/to/file/map.txt

RewriteRule ^/(.*\.(png|gif|jpg)) http://${servers:static}/$1 [NC,P,L]
RewriteRule ^/(.*) http://${servers:dynamic}/$1 [P,L]
Hash File

No comments:

Post a Comment