我从Stackoverflow搜索并尝试了所有可能的解决方案,但似乎没有什么适合我的情况。
我想重写这个URL:http://www.example.com/test/name.php?name=somename
显示为http://www.example.com/test/somename
这是我当前在htaccess文件
中的内容RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^test/?$ /test/name.php/?name=$1 [NC,L,QSA]
如果有人能在这里借给一些帮助,我会很感激,因为我已经被困在这个超过一天。谢谢!
RewriteRule ^test/?$ /test/name.php/?name=$1 [NC,L,QSA]
^---- "0 or 1 of the previous"
因为这里有^$
锚定,你基本上是在说
/test/
/test
是唯一两个可以匹配的uri。你可能想要
RewriteRule ^test/(.*)$ /test/name.php?name=$1
。"一个以test/
开头的url,并使用test/
之后的所有内容作为名称参数"。
尝试使用RewriteBase!
RewriteEngine On
RewriteBase /test/
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . name.php?name=$1