3

Is there any straightforward way to change the case of any URL using mod_rewrite?

I thought this was pretty trivial... apparently not.

Examples:

http://example.com/id to http://example.com/ID

http://example.com/id/123 to http://example.com/ID/123

and so forth.

Yeti
  • 5,379
  • 9
  • 44
  • 70

3 Answers3

3

mod_rewrite has some internal functions you can use for a mapping. One of them is toupper that converts letters to uppercase:

RewriteMap uppercase int:toupper

RewriteRule [a-z] %{uppercase:%{REQUEST_URI}} [L,R=301]
Gumbo
  • 620,600
  • 104
  • 758
  • 828
2

I was looking to change case of only the ID. This one did the trick:

RewriteRule ^id(.*)$ /ID$1  [QSA,R,L]
Yeti
  • 5,379
  • 9
  • 44
  • 70
1
RewriteMap uppercase int:toupper
RewriteRule ^/(^/)*$ /${uppercase:$1}  [L]
RewriteRule ^/([^/]*)/(.*)$ /${uppercase:$1}/$2 [L]

(syntax unchecked)

Zed
  • 55,616
  • 9
  • 73
  • 100