php - .htaccess 重写多查询字符串,只有一个查询作为路径
问题描述
我尝试从 .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 ”查询的常规获取字符串。
如-
https://example.com/?page=contact2&query15=test14&query25=test24&query35=test34
将输出 $_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
推荐阅读
- javascript - 函数式编程将 Monad 数组转换为单个 Monad 数组
- javascript - jquery ajax中下拉的onchange函数
- php - 如何从两个数组中自动选择相同的值
- javascript - Datepicker 模式弹出窗口无法正常工作 - jQuery
- python - python的任何缓存分析器?
- ruby - .each 循环中的 Chef ERB 模板变量
- android - 如何在 API 23 或更高版本中禁用 Android 中的运行时权限?
- ant-media-server - Ant 媒体服务器自定义
- python - 值未由函数更新
- python - 为什么 Python 多处理调用未指定的代码?