重写规则和放大器;逃脱(EN codeD)内的URL正斜杠斜杠、放大器、重写、规则

2023-09-02 09:53:22 作者:愿时光静好ζ

我已经开发了这个重写规则已被伟大的工作,直到我发现了一个问题。

这是规则在这里:

 的RewriteCond%{REQUEST_URI} ^ /([^ /] +)/([^ /] +)/([^ /] +)/(。*)$
 的RewriteCond%{DOCUMENT_ROOT} / 1%/ 2%/%4.php -f
 重写规则^ /%1/%2/%4.php?id=%3 [QSA,L]
 

该URL格式是像这样:/首页/服务/ ID 的/脚本名 注意, ID 的是动态的,它检查文件是否存在时,重写规则不走不行。

但在这一种情况下,我发现,我使用的ID之一包含了一个%2F - 这时候去codeD转换为正斜杠(/) - 由于某种原因,重写的时候休息,因为它认为还有另一个目录规则。

我的问题是,为什么是%2F感德$ C $的重写规则内的CD,我怎么可以设计一个解决方案吗? - $ P $不是一个快速的黑客或更改ID pferably其他 解决方案

我想你需要添加的 B 标志重写规则,像这样的:

 重写规则^ /%1/%2/%4.php?id=%3 [QSA,L,B]
 
表情 python爬虫使用代理池爬取拉勾网python招聘信息 qq 42689278的博客 ... 表情

勾选此链接了解详情。

I have developed this RewriteRule which has been working great, up until I discovered an issue.

This is the rule here:

 RewriteCond %{REQUEST_URI} ^/([^/]+)/([^/]+)/([^/]+)/(.*)$
 RewriteCond %{DOCUMENT_ROOT}/%1/%2/%4.php -f
 RewriteRule ^ /%1/%2/%4.php?id=%3 [QSA,L]

The URL format is like so: /home/service/ID/scriptname note that ID is dynamic and the RewriteRule does not take not of it when checking for the files existence.

But in this one scenario I found out, one of the IDs I'm using contains a '%2F' - which when decoded is translated to a forward slash (/) - And for some reason, the Rewrite rule when breaks because it thinks there's another directory.

My question is, why is %2F being decoded within the RewriteRule, and how can I engineer a solution? - Preferably other than a quick hack or changing the ID.

解决方案

I think you need to add the B flag in the rewrite rule, like this:

RewriteRule ^ /%1/%2/%4.php?id=%3 [QSA,L,B]

Check this link for more information.