【问题标题】:htaccess rewrite everything with and without question markhtaccess 用问号和不带问号重写所有内容
【发布时间】: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


    【解决方案1】:

    你在发布问题几分钟后想出答案的那一刻......

    无论如何我想出了这个:

    RewriteRule ^(.*)?$ index.php?page=$1&%{QUERY_STRING} [L]
    
    RewriteRule ^(.*) index.php?p=$1 [L]
    

    【讨论】:

      猜你喜欢
      • 2013-09-03
      • 2021-08-21
      • 1970-01-01
      • 1970-01-01
      • 2013-10-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-08-12
      相关资源
      最近更新 更多