相邻(非领导,不拖动)前向斜线是“归一化”在mod_rewrite rewriteCond中重写以创建查询参数
每个人!
我的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/(.+)\.jpgquot;
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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
因此,从技术上讲,这并不能回答我的问题,因为似乎没有办法防止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.