.htaccess 重写
我不知道这是否是正确的区域,但这里是:
我有一个 RewriteRule
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/1016/2063/test.html [L,NC]
工作正常,因为我已经对 ID 进行了硬编码。现在,当我执行类似的操作时,
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/$2/2063/test.html [L,NC]
重写不会工作,我找不到页面。真正奇怪的部分是 $4
可以工作,所以如果我做类似的事情
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/1016/$4/test.html [L,NC]
它可以工作,但是 3 及以下的任何东西都不起作用。有什么想法吗?我正在使用的网址是 http://www.escience.ca/kids/RENDER/1016/ 2063/P2063.html
如您所见,$3
和 $4
是完全相同的 ID,这就是我的第三个示例有效的原因。
I don't know if this is the right area, but here goes:
I have a RewriteRule
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/1016/2063/test.html [L,NC]
that works fine because I've hardcoded the IDs in. Now when I do something like
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/$2/2063/test.html [L,NC]
The rewrite doesn't work, I get page not found. The really odd part is that $4
works, so if I do something like
RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/1016/$4/test.html [L,NC]
it works, but anything 3 and under doesn't work. Any ideas? The URL that I am using is
http://www.escience.ca/kids/RENDER/1016/2063/P2063.html
As you can see, $3
and $4
are the exact same IDs, so that's why my third example works.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
查看您的正则表达式组:
很明显为什么它不起作用 - $2 不是您期望的数字。如果您忘记了编号,也许您应该对复杂的正则表达式使用命名组。顺便说一句,您可以使用
?:
运算符将正则表达式组排除在分组之外(例如“(?:ungrouped)(dollar1)(dollar2)”)。Look at your regex groups:
It should be obvious why it doesn't work - $2 is not the number you expected. Maybe you should use named groups for complex regular expressions if you loose track of the numbering. You can exclude regex groups from being grouped by using the
?:
operator, by the way (for example "(?:ungrouped)(dollar1)(dollar2)").