Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/6.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_Mod Rewrite - Fatal编程技术网

Php htaccess查询字符串转换

Php htaccess查询字符串转换,php,.htaccess,mod-rewrite,Php,.htaccess,Mod Rewrite,我有以下URL结构: http://example.com/file.php?section=sectionName 我想将此转换为: http://example.com/file/sectionName 当前尝试似乎不起作用: RewriteRule ^(.*)$ file.php?section=$1 [L,QSA] 并且似乎会干扰另一次重写,即从文件名中剥离.php结尾: RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-f Re

我有以下URL结构:

http://example.com/file.php?section=sectionName
我想将此转换为:

http://example.com/file/sectionName
当前尝试似乎不起作用:

RewriteRule ^(.*)$ file.php?section=$1 [L,QSA]
并且似乎会干扰另一次重写,即从文件名中剥离
.php
结尾:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.php [L]

您可以使用此htaccess:

RewriteEngine On

#rewrite /file => file.php
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule ^([^\.]+)$ $1.php [L]
#rewrite /file/foobar => file.php?section=foobar
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^file/([^/]+)/?$ /file.php?section=$1 [NC,L]

不幸的是,这似乎不起作用,我仍然得到
http://example.com/file.php?section=sectionName
。你将使用什么url?它不是公共url,在测试环境中是本地的。Re1)你的意思是“当你键入“/file/foobar”时,你会被重定向到“/file.php”部分吗?对不起,我的错,这完全是应该的。抱歉。