相邻(非领导,不拖动)前向斜线是“归一化”在mod_rewrite rewriteCond中重写以创建查询参数

发布于 2025-02-11 00:53:38 字数 1071 浏览 2 评论 0原文

每个人!

我的URL看起来像这样:

/path/to/renderer/SPECIALKEY.jpg

我想将它们重写为:

/path/to/renderer/?ID=SPECIALKEY

问题是SpecialKey可能包含两个相邻的前向斜线,例如:

/path/to/renderer/HELLO/GOOD//BYE.jpg

关注这个答案在stackoverflow中,我修改了.htaccess以包含:

RewriteCond "%{REQUEST_URI}" "^/?path/to/renderer/(.+)\.jpg$"
RewriteRule "^.*$" "/path/to/renderer/?ID=%1" [PT,QSA]

但是双斜切仍被“归一化”。

/path/path/to/renderer/index.php,如果我说:

echo $_SERVER[ 'REQUEST_URI' ] . "\n" . $_GET[ 'ID' ] . "\n";

for /path/path/path/to/renderer/hello/good/good/good/bye.jpg,i' LL Get:

/path/to/renderer/HELLO/GOOD//BYE.jpg
HELLO/GOOD/BYE

我必须放入.htaccess才能得到:(

/path/to/renderer/HELLO/GOOD//BYE.jpg
HELLO/GOOD//BYE

最后一行而不是两个斜线)?

提前致谢!

everyone!

I have URLs that look something like this:

/path/to/renderer/SPECIALKEY.jpg

And I want to rewrite them to:

/path/to/renderer/?ID=SPECIALKEY

The problem is that SPECIALKEY may contain two adjacent forward slashes, such as:

/path/to/renderer/HELLO/GOOD//BYE.jpg

Following this answer in StackOverflow, I modified .htaccess to contain:

RewriteCond "%{REQUEST_URI}" "^/?path/to/renderer/(.+)\.jpg
quot;
RewriteRule "^.*
quot; "/path/to/renderer/?ID=%1" [PT,QSA]

But the double-slashes are still getting "normalized".

Inside /path/to/renderer/index.php, if I put:

echo $_SERVER[ 'REQUEST_URI' ] . "\n" . $_GET[ 'ID' ] . "\n";

Then for /path/to/renderer/HELLO/GOOD//BYE.jpg, I'll get:

/path/to/renderer/HELLO/GOOD//BYE.jpg
HELLO/GOOD/BYE

What must I put in .htaccess to get:

/path/to/renderer/HELLO/GOOD//BYE.jpg
HELLO/GOOD//BYE

(with three slashes on the last line instead of two)?

Thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

生活了然无味 2025-02-18 00:53:38

因此,从技术上讲,这并不能回答我的问题,因为似乎没有办法防止Apache“正常化”两个斜率。取而代之的是,我为解决这个问题所做的事情是:

每当真正的SpecialKey包含//时,我将其替换为/_。另外,如果第一个字符是/,则将其替换为_。我将结果放在URL中,而不是真正的特别关键。

因为_从不出现在真正的SpecialKey内真正的特别关键。

So this doesn't technically answer my question, because it seems there is no way to prevent Apache from "normalizing" two slashes down to one. Instead, what I did to solve the problem is:

Any time the real SPECIALKEY contains //, I replace it with /_. Also, if the first character is a /, I replace it with _. I put the result in the URL instead of the real SPECIALKEY.

Because _ never appears within the real SPECIALKEY, when the page receives the modified key, it replaces every _ with a / before processing it as the real SPECIALKEY.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文