dsfhe34889 2017-07-11 19:22
浏览 64

当URL包含%字符时使用Apache重写模块向每个%添加“52”

I need to modify the path of a long URL which includes % characters in it, for example:

https://www.my-geoserver.co.uk/geoserver/HNT_Demo/wms?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetMap&FORMAT=image%2Fpng&TRANSPARENT=true&LAYERS=HNT_Demo%3ANO2_Wed_h18_WGS&TILED=true&login=admin&WIDTH=256&HEIGHT=256&CRS=EPSG%3A3857&STYLES=&BBOX=-132083.18487678468%2C6780270.1570082735%2C-127191.2150665334%2C6785162.126818525

When i attempt to use Apache rewrite module, I notice that the % characters are causing problems, so for example the section here:

image%2Fpng

Upon rewrite becomes (notice 52 has appeared):

image%252Fpng

%2F is the URL Encoded value of a forward slash, so I can't believe this is an uncommon problem.

The code I'm using (for experimental purposes) is:

RewriteCond %{QUERY_STRING} ^(.*)login=[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]

Which should simply remove the login variable which it does. But I also get a modification of the % values throughout the URL, where in all cases 52 is appearing which I don't think is related to the RewriteRule per say.

Is there a way to allow RewriteRule to work with % values in the URL? I have tried the following flags (somewhat desperately):

  • NC
  • NE
  • QSA

But with no luck.

Additional:

I've just found this very old bug report which shows the same behavior of % being 'escaped' to %25. Is this possibly a bug?

https://bz.apache.org/bugzilla/show_bug.cgi?id=39746

This bug is referring to using a reverse proxy and the error being in mod_proxy, well I'm using a reverse proxy to host Tomcat, could this be related?

Additional 2:

The answer to a question here:

the auto urldecode in apache mod_rewrite

Suggests using server variables to get around the % issue, unfortunately, I already am using them. I tried replacing QUERY_STRING with REQUEST_URI and THE_REQUEST, both of which result in the same behaviour:

RewriteCond %{THE_REQUEST} ^(.*)login=[^&]*(?:&(.*)|)$ [NC]
RewriteRule ^ %{REQUEST_URI}?%1%2 [R=301,L]
  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 程序不包含适用于入口点的静态Main方法
    • ¥15 素材场景中光线烘焙后灯光失效
    • ¥15 请教一下各位,为什么我这个没有实现模拟点击
    • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
    • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
    • ¥20 有关区间dp的问题求解
    • ¥15 多电路系统共用电源的串扰问题
    • ¥15 slam rangenet++配置
    • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
    • ¥15 ubuntu子系统密码忘记