htaccess如何在url中重写编码的斜杠 [英] htaccess howto rewrite an encoded slash in url

查看:79
本文介绍了htaccess如何在url中重写编码的斜杠的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有编码斜杠(%2F)的URL,我无法获得重写规则来正确捕获此问题.

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

我的网址是:

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]

我还尝试过在上面添加QSA.

I've also tried adding QSA to above.

此处上也有类似的问题,但这是基于IIS和.NET的

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

我正在运行LAMP堆栈

I'm running LAMP stack

推荐答案

出于安全原因,Apache拒绝了%2F.请参见 urlencoded正斜杠会破坏URL

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

您可以使用 AllowEncodedSlashes 关闭此功能您的服务器配置中的指令.

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

但是,如果您可以控制这部分代码,则最好对URL进行编码.

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

这篇关于htaccess如何在url中重写编码的斜杠的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆