Php htaccess查询字符串转换
我有以下URL结构: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
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”部分吗?对不起,我的错,这完全是应该的。抱歉。