【发布时间】:2018-02-20 09:24:50
【问题描述】:
多年来,我一直在使用几行基本的代码来重写路由器的所有 URL。主要的 RewriteRule 是:
RewriteRule ^(.*) index.php?page=$1 [L]
我现在想扩展它,将问号后面的所有内容添加为另一个通配符。例如 /register?username=Marco 变成 index.php?page=register&username=Marco 和 /articles/1/shirt?color=red&size=L 变成 index.php?page=articles/1/shirt&color=red&size=L
到目前为止,我想出了以下内容,但这只会匹配问号后面的所有内容,并且仍将其放在页面变量中。
#rewrite problem
RewriteCond %{QUERY_STRING} ^(.*)$
RewriteRule ^(.*)?$ index.php?p=$1&%2 [L]
在网上寻找这个我只找到了如何重写查询字符串或其他所有内容,没有任何组合。因此,欢迎提供一些帮助。
提前致谢!
【问题讨论】:
标签: .htaccess