我正在使用 mod_rewrite 将 .html 重写为 .php。
RewriteRule ^([0-9a-zA-Z-_]+)\.html$ index.php?p=$1 [L]
但是,我在 URL 中使用 $_GET 时遇到了问题。如果请求的 URL 是这种格式,它工作正常:index.php?a=f1
但是,如果将其重写为 home.html?a=f1
,则什么都没有。
假设它只是浏览器在点击 .html 后停止阅读。有什么办法可以做到这一点吗?
最佳答案
您需要添加 QSA
标志:
RewriteRule ^([0-9a-zA-Z-_]+)\.html$ index.php?p=$1 [QSA,L]
原因最好在文档中解释:
When the replacement URI contains a query string, the default behavior of RewriteRule is to discard the existing query string, and replace it with the newly generated one. Using the [QSA] flag causes the query strings to be combined.
关于php - $_GET 变量在 mod_rewrite 将 .html 重写为 .php 时消失,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11234188/