【问题标题】:.htaccess rewrite for multi-query string with only one query as path.htaccess 重写多查询字符串,只有一个查询作为路径
【发布时间】:2020-11-03 15:35:13
【问题描述】:

我尝试从 .htaccess 重写

https://example.com/?page=contact&query1=test1&query2=test2

https://example.com/contact/?query1=test1&query2=test2

输出为

Array
(
    [page] => contact
    [query1] => test1
    [query2] => test2
)

我尝试了下面的重写,但没有得到输出-

RewriteEngine On
RewriteRule ^(.*?)//?(.*)$ /?page=$1&$2 [NC,L]

在这里我应该包括我可以在 https://example.com/contact/ 之后进行任何查询,输出如下,类似于带有“page”查询的常规获取字符串。 p>

比如-

https://example.com/?page=contact2&query15=test14&query25=test24&query35=test34

将输出 $_GET 查询字符串

Array
(
    [page] => contact2
    [query15] => test14
    [query25] => test24
    [query35] => test34
)

【问题讨论】:

    标签: php apache mod-rewrite query-string


    【解决方案1】:

    以下规则应该可以解决问题:

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{QUERY_STRING} ^(.*)$
    RewriteRule ^/?([^/]+).* /?page=$1&%1 [NC,L]
    

    我们检查打开的链接是否不是有效/现有的文件或目录,然后我们捕获当前的查询字符串,最后我们重写访问的页面。

    查看它的实际效果:https://htaccess.madewithlove.be?share=1e473616-5364-5718-8819-a8032a5319c1

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-10-11
      • 2021-12-10
      • 1970-01-01
      • 2011-03-07
      • 2015-01-08
      • 2017-09-19
      • 1970-01-01
      • 2015-01-03
      相关资源
      最近更新 更多