How can I forward a query string using htaccess?

微笑、不失礼 提交于 2019-12-10 11:09:38

问题


I am using this, at present, to rewrite URLS:

RewriteEngine on
RewriteRule ^([^/?\.]+)$ /page.php?name=$1 [NC]

So mysite.com/home gets rewritten to mysite.com/page.php?name=home

How can I make it also rewrite mysite.com/home?param=value to mysite.com/page.php?name=home&param=value? Ideally, I'd like this to work for any name/value querystring pairs.

Am I missing something obvious?


回答1:


Check out the "capturing variables" section at http://corz.org/serv/tricks/htaccess2.php

It says that if you add [QSA] to the end of the rewrite rule, it should pass variables through the rewrite.




回答2:


This made it work:

RewriteEngine on
RewriteRule ^([^/?\.]+)$ /page.php?name=$1&%{QUERY_STRING} [NC]


来源:https://stackoverflow.com/questions/3024316/how-can-i-forward-a-query-string-using-htaccess

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