繁体   English   中英

.htaccess 重写多查询字符串,只有一个查询作为路径

[英].htaccess rewrite for multi-query string with only one query as path

我尝试从 .htaccess 重写

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

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

与 output 作为

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

我尝试了下面的重写,但未能获得输出-

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

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

如-

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

将 output 的 $_GET 查询字符串

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

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

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM