使用mod_rewrite RewriteRule重写所有查询以不需要.php扩展名

dre*_*ves 6 php url mod-rewrite friendly-url

我想要所有的疑问

http://mysite.com/something/otherthing?foo=bar&x=y
Run Code Online (Sandbox Code Playgroud)

被重写为

http://mysite.com/something/otherthing.php?foo=bar&x=y
Run Code Online (Sandbox Code Playgroud)

换句话说,只需将.php扩展名设为可选的.

Chr*_*tow 6

我会这样做的.基本上,如果文件不存在,请尝试添加.php.

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ $1.php [QSA,L]
Run Code Online (Sandbox Code Playgroud)