我一直在谷歌和stackoverflow上搜索,找到了大量答案,但似乎没有一个对我有效。
基本上,我想要的是重写我的url localhost/index.php?page=1到localhost/1,同时仍然保持查询活动。
现在,我已经用以下代码删除了.php:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^'.]+)$ $1.php [NC,L]
但是删除Query似乎根本不起作用。
请帮帮我。
你的规则与你想要做的不匹配。你告诉它接受任何东西中的一个或多个,并将其变成blah.php
(就像http://localhost/blah
->http://localhost/blah.php
)。
你正在寻找类似RewriteRule ^([0-9]+)$ index.php?page=$1 [NC,L]
的东西。
顺便说一下,你的语言有点落后。您没有将index.php?page=1
重写为localhost/1
;您正在将localhost/1
重写为index.php?page=1
(实际上是1
到index.php?page=1
)。