以下重写规则正在一个简单的PHP站点上使用.htaccess:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /test/
RewriteRule ^index\.php$ - [L]
RewriteRule ^([a-zA-Z-]+)/?$ /test/index.php?m=$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /test/index.php [L]
</IfModule>
以下网址正常运作:
domain.com/test/index.php?m=profile
domain.com/test/profile
domain.com/test/profile/
但是,重写时会丢失其他查询参数:
domain.com/test/index.php?m=profile&id=2000 ==> works
domain.com/test/profile?id=2000 ==> does not work
domain.com/test/profile?id=2000 ==> does not work
任何帮助表示感谢。
答案 0 :(得分:0)
更改此行:
RewriteRule ^([a-zA-Z-]+)/?$ /test/index.php?m=$1 [L]
包含QSA
标志:
RewriteRule ^([a-zA-Z-]+)/?$ /test/index.php?m=$1 [L,QSA]
告诉apache将现有查询字符串附加到新查询字符串(m=$1
)。