htaccess howto rewrite an encoded slash in url

空扰寡人 提交于 2020-05-16 13:55:52

问题


I have URL with an encoded slash (%2F) and I cannot get rewrite rules to catch this correctly.

My URL is:

http://example.com/some-path/description%2Frest-of-description/1101

I've tried rewrites like:-

# is the %2F interpreted as a path separator
RewriteRule ^some-path/(.*)/(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L]
# or is it as an encoded string
RewriteRule ^some-path/(.*)%2F(.*)/(.*)$ /property/view?ref=$3 [B,R=301,L]
# or even double encoded
RewriteRule ^some-path/(.*)%252F(.*)/(.*)$ /villas/$1-$2/$3 [B,R=301,NE,L]

I've also tried adding QSA to above.

There is a similar question on SO here but it's IIS and .NET based

I'm running LAMP stack


回答1:


For security reasons Apache deny %2F. See urlencoded Forward slash is breaking URL

You can turn off this with AllowEncodedSlashes directive in your server config.

But it would be better if you encode the URL if you have control of this part of the code.



来源:https://stackoverflow.com/questions/34451993/htaccess-howto-rewrite-an-encoded-slash-in-url

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