Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php .htaccess重写查询字符串不工作_Php_.htaccess - Fatal编程技术网

Php .htaccess重写查询字符串不工作

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

我已经从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

相反。“一个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