.htaccess 重写

发布于 2024-09-25 11:30:13 字数 855 浏览 1 评论 0原文

我不知道这是否是正确的区域,但这里是:

我有一个 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 技术交流群。

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

发布评论

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

评论(1

迷爱 2024-10-02 11:30:13

查看您的正则表达式组:

RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/$2/2063/test.html [L,NC]
             $1          $2           $3    $4     $5

很明显为什么它不起作用 - $2 不是您期望的数字。如果您忘记了编号,也许您应该对复杂的正则表达式使用命名组。顺便说一句,您可以使用 ?: 运算符将正则表达式组排除在分组之外(例如“(?:ungrouped)(dollar1)(dollar2)”)。

Look at your regex groups:

RewriteRule ^(eScience/)?(\w+)/RENDER/(\d+)/(\d+)/P(\d+)\.html$ /RENDER/escience/kids/$2/2063/test.html [L,NC]
             $1          $2           $3    $4     $5

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)").

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