HTAccess - Confusing clean url's

人盡茶涼 提交于 2019-12-20 07:16:35

问题


If i wanted to simply redirect /clients/page/ to /clients.php?view=page i would use something as simple as this, it works great.

Options +FollowSymlinks
RewriteEngine on
RewriteRule ^clients/([^/]+) /clients.php?section=$1&$2 [NC]

If i had for example, a url like: /clients/page/?name=Tom how could i transfer those HTTP GET variables to a simple url like /clients.php?view=page&name=Tom i have tried and failed.

Any ideas?


回答1:


I think you can use the [QSA] flag, which stands for Query String Append. This means that you can add variables to the Query String easily:

RewriteRule ^clients/([^/]+) /clients.php?section=$1 [QSA, NC]



回答2:


I think you're looking for the [QSA] flag on the RewriteRule:

http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#RewriteRule

That should cause mod_rewrite to preserve your original query parameters.

RewriteRule ^clients/([^/]+) /clients.php?section=$1 [QSA,NC]


来源:https://stackoverflow.com/questions/2088804/htaccess-confusing-clean-urls

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