我从互联网上得到了这个重写规则:
# To externally redirect /dir/foo.php to /dir/foo
RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]
该规则运行良好,但现在当我尝试发送 POST 消息时,该规则还将重写 GET 方法。这是我的表格:
<form action="check.php" method="post">
<input type="text" name="email" id="email"/>
<input type='submit' value='check'>
</form>
这是我从服务器得到的(var_dump($_SERVER))
["REQUEST_METHOD"]=>
string(3) "GET"
我不太熟悉重写规则。你能告诉我如何修复它,以便它仍然处理 php 文件扩展名但不会触及 REQUEST_METHOD 部分(从 POST 到 GET)?
谢谢你。
更新完整规则:
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 [L,NC] #[R,L,NC]
## To internally redirect /dir/foo to /dir/foo.php
RewriteCond %{REQUEST_FILENAME}.php -f [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]