通过 Apache 重写规则附加查询字符串
如何重写以下内容:
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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用
RewriteRule
,您只能测试 URI 路径,而不能测试查询。您需要使用RewriteCond
来执行此操作,例如:这会将参数 type 添加到查询中并进行内部重写。如果您想要外部重定向,请添加R标志。
With
RewriteRule
you can only test the URI path but not the query. You need to useRewriteCond
to do so, for example:This will add the parameter type to the query and do an internal rewrite. If you want an external redirect, add the R flag.