Options +FollowSymLinks -MultiViews
# Turn mod_rewrite on
RewriteEngine On
RewriteBase /
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]
上述工作至于从我的所有网址中删除.php
。是否有可能删除网址后的所有参数(如果存在)?例如,将site.com/index.php?id=24
重写为site.com/index
答案 0 :(得分:1)
在%1之后添加?
:
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1? [R,L,NC]
# here ---------^
当重写规则的目标URI中有?
时,除非有QSA
标记,否则规则不会附加查询字符串。