重写请求,保留参数并设置新参数

发布于 2025-01-08 01:53:07 字数 630 浏览 1 评论 0原文

我正在尝试重写对索引页的请求,保留查询字符串参数并添加一个新参数。

示例:

Request: products/?limit=10&page=4&as=many&params=as&I=need
Rewrite to: index.php?page=pages&limit=10&page=4&as=many&params=as&I=need

// index.php
$_REQUEST = array(
    'page' => 'products'
    'limit' => '10',
    'page' => '4',
    'as' => 'many'
    'params' => 'as',
    'I' => 'need'
);

我识别请求,设置参数并重写到正确的页面。但我无法保留旧的查询字符串参数。

RewriteRule ^products(.*) index.php?page=products [NC,L]
// index.php
$_REQUEST = array(
    'page' => 'products'
);

TIA

I am trying to rewrite the request to the index page, keeping the query string params and adding a new one.

Exemple:

Request: products/?limit=10&page=4&as=many¶ms=as&I=need
Rewrite to: index.php?page=pages&limit=10&page=4&as=many¶ms=as&I=need

// index.php
$_REQUEST = array(
    'page' => 'products'
    'limit' => '10',
    'page' => '4',
    'as' => 'many'
    'params' => 'as',
    'I' => 'need'
);

I identify the request, set a param and rewrite to the correct page. I cannot keep the old query string params though.

RewriteRule ^products(.*) index.php?page=products [NC,L]
// index.php
$_REQUEST = array(
    'page' => 'products'
);

TIA

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

疑心病 2025-01-15 01:53:07

[QSA] 标志将任何替换参数附加到现有集合中 - 例如,在第二个示例中使用 [NC,QSA,L]

如果这适合您,我可以请您检查我的答案是否已解决吗?

The [QSA] flag appends any substitution parameters to the existing set -- e.g. in your second example use [NC,QSA,L].

If that suits you, may I ask you to check my answer as solved?

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