如何捕获“子部分”重写规则中的 URL?

发布于 2024-09-01 04:54:44 字数 589 浏览 2 评论 0原文

我知道标题有点奇怪,但 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 技术交流群。

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

发布评论

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

评论(1

北凤男飞 2024-09-08 04:54:44

您可以简单地使用 QSA 标志将原始查询附加到新查询中:

RewriteRule ^user/(\d+)/page$    something.pl?id=$1 [L,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:

RewriteRule ^user/(\d+)/page$    something.pl?id=$1 [L,QSA]

Now a request of /user/xxx/page?error=yyy will get rewritten to /something.pl?id=xxx&error=yyy.

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