Append Query String via Apache Rewrite Rule

断了今生、忘了曾经 提交于 2019-12-12 01:44:00

问题


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]

回答1:


RewriteRule ^html page/([^/\.]+)?$ index.php?action=search_refine&type=$1 [L]



回答2:


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.



来源:https://stackoverflow.com/questions/3887496/append-query-string-via-apache-rewrite-rule

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!