mod_rewrite - change URL case

前端 未结 3 2016
北海茫月
北海茫月 2020-12-04 02:32

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

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

Examples:

ht

相关标签:
3条回答
  • I was looking to change case of only the ID. This one did the trick:

    RewriteRule ^id(.*)$ /ID$1  [QSA,R,L]
    
    0 讨论(0)
  • 2020-12-04 03:21

    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]
    
    0 讨论(0)
  • 2020-12-04 03:21
    RewriteMap uppercase int:toupper
    RewriteRule ^/(^/)*$ /${uppercase:$1}  [L]
    RewriteRule ^/([^/]*)/(.*)$ /${uppercase:$1}/$2 [L]
    

    (syntax unchecked)

    0 讨论(0)
提交回复
热议问题