我有以下网址结构:
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]
答案 0 :(得分:1)
您可以使用此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]