如何捕获“子部分”重写规则中的 URL?
我知道标题有点奇怪,但 URL 如下所示:
/user/xxx/page
/user/xxx/page?error=yyy
第一个 URL 的规则如下所示:
RewriteRule ^user/(\d+)/page$ something.pl?id=$1 [L]
为了使其与第二个 URL 一起使用,它变成:
RewriteRule ^user/(\d+)/page(error=\d+)?$ something.pl?id=$1 [L]
我的问题是...如何我要捕获错误号吗?我尝试了这两种方法:
RewriteRule ^user/(\d+)/page(error=(\d+))?$ something.pl?id=$1&error=$2 [L]
RewriteRule ^user/(\d+)/page(error=(\d+))?$ something.pl?id=$1&error=$3 [L]
但它不起作用...
我该怎么做?
I know the title is a little bit strange, but here is what the URLs look like:
/user/xxx/page
/user/xxx/page?error=yyy
The rule for the first URL looks something like this:
RewriteRule ^user/(\d+)/page$ something.pl?id=$1 [L]
And to make it work with the second URL, it becomes:
RewriteRule ^user/(\d+)/page(error=\d+)?$ something.pl?id=$1 [L]
My question is... how do I capture the error number? I tried both of these:
RewriteRule ^user/(\d+)/page(error=(\d+))?$ something.pl?id=$1&error=$2 [L]
RewriteRule ^user/(\d+)/page(error=(\d+))?$ something.pl?id=$1&error=$3 [L]
But it isn't working...
How can I do this?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以简单地使用 QSA 标志将原始查询附加到新查询中:
现在
/user/xxx/page?error=yyy
的请求将被重写为/something.pl?id=xxx&error=yyy
。You can simply use the QSA flag to get the original query appended to the new one:
Now a request of
/user/xxx/page?error=yyy
will get rewritten to/something.pl?id=xxx&error=yyy
.