通过 Apache 重写规则附加查询字符串

发布于 2024-09-26 18:29:08 字数 436 浏览 1 评论 0原文

如何重写以下内容:

http://www.mydomain.com/my-page.html< /a> 到 http://www.mydomain.com/my-page.html ?type=1

尝试了以下操作,但没有成功:

RewriteRule /car-covers.html$ /car-covers.html?type=$1 [R=301,L]

RewriteRule ^car-covers.html$ car-covers.html?type=$1 [QSA,L]

How can I rewrite the following:

http://www.mydomain.com/my-page.html to http://www.mydomain.com/my-page.html?type=1

Tried the following without any luck:

RewriteRule /car-covers.html$ /car-covers.html?type=$1 [R=301,L]

RewriteRule ^car-covers.html$ car-covers.html?type=$1 [QSA,L]

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

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

发布评论

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

评论(2

心作怪 2024-10-03 18:29:08
RewriteRule ^html page/([^/\.]+)?$ index.php?action=search_refine&type=$1 [L]
RewriteRule ^html page/([^/\.]+)?$ index.php?action=search_refine&type=$1 [L]
黯然#的苍凉 2024-10-03 18:29:08

使用RewriteRule,您只能测试 URI 路径,而不能测试查询。您需要使用 RewriteCond 来执行此操作,例如:

RewriteCond %{QUERY} !(^|&)type=
RewriteRule ^car-covers\.html$ car-covers.html?type=$1 [QSA,L]

这会将参数 type 添加到查询中并进行内部重写。如果您想要外部重定向,请添加R标志。

With RewriteRule you can only test the URI path but not the query. You need to use RewriteCond to do so, for example:

RewriteCond %{QUERY} !(^|&)type=
RewriteRule ^car-covers\.html$ car-covers.html?type=$1 [QSA,L]

This will add the parameter type to the query and do an internal rewrite. If you want an external redirect, add the R flag.

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