Php .htaccess重写查询字符串不工作
我已经从Stackoverflow搜索并尝试了所有可能的解决方案,但似乎对我的案例没有任何效果 我正在尝试重写此URL:Php .htaccess重写查询字符串不工作,php,.htaccess,Php,.htaccess,我已经从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_F
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
相反。“一个url,它以
test/
开头,并使用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
这里有“.”是任何请求。在
test/…
之后没有正则表达式占位符,OP已经在使用根相对替换,因此实际上不需要RewriteBase
。