mod_rewrite - change URL case

我是研究僧i 提交于 2019-12-17 14:54:02

问题


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.


回答1:


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]



回答2:


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

RewriteRule ^id(.*)$ /ID$1  [QSA,R,L]



回答3:


RewriteMap uppercase int:toupper
RewriteRule ^/(^/)*$ /${uppercase:$1}  [L]
RewriteRule ^/([^/]*)/(.*)$ /${uppercase:$1}/$2 [L]

(syntax unchecked)



来源:https://stackoverflow.com/questions/1353807/mod-rewrite-change-url-case

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!