我想使用.htaccess 将"example.com?pid=12"重定向到"example.com/index.php?pid=12"
我在.htaccess文件中写了以下内容。
RewriteEngine On
RewriteBase /
RewriteCond %{QUERY_STRING} pid [NC]
RewriteRule ^ example.com/index.php'?$1 [R=301,L]
但它并没有附加查询字符串。
您可以使用:
RewriteEngine On
RewriteCond %{QUERY_STRING} ^pid='d+ [NC]
RewriteRule ^/?$ /index.php [R=301,L]
查询字符串会自动转移到目标。
您需要在RewriteRule
中添加查询字符串附加标志[QSA]
,因为您正在使用"?"修改查询字符串
更多信息:https://wiki.apache.org/httpd/RewriteQueryString