简体   繁体   English

RewriteCond 和 RewriteRule 可以停止 POST 吗?

[英]RewriteCond and RewriteRule can stop POST?

In my .htaccess I have these instructions:在我的 .htaccess 我有这些说明:

RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
RewriteRule ^ %1 [R,L,NC]

RewriteCond %{REQUEST_FILENAME}.php [NC]
RewriteRule ^ %{REQUEST_URI}.php [L]

Now I'm facing problems to fire any $_POST.现在我面临着解雇任何 $_POST 的问题。 No way, neither with php nor html nor ajax nor jquery.没办法,既没有 php 也没有 html 也没有 ajax 也没有 ZD223E1439188E468349D52422。 No POST values are passed.没有传递 POST 值。 They simply don't pass to destination file.它们根本不会传递到目标文件。 Can be a problem caused by the above rules and conditions?会不会是上述规则和条件导致的问题? If yes, how can I get the same result without blocking POST?如果是,如何在不阻止 POST 的情况下获得相同的结果? My need is to externally redirect /dir/foo.php to /dir/foo and to internally redirect /dir/foo to /dir/foo.php.我需要从外部将 /dir/foo.php 重定向到 /dir/foo 并在内部将 /dir/foo 重定向到 /dir/foo.php。

your .htaccess should be like this你的.htaccess应该是这样的

RewriteEngine On
RewriteCond %{REQUEST_FILENAME}.php -f
RewriteRule !.*\.php$ %{REQUEST_FILENAME}.php [L]

and it will work above code only remove file extension but if you want to force redirection then your .htaccess should be like this它会在上面的代码中工作,只删除文件扩展名,但如果你想强制重定向,那么你的.htaccess应该是这样的

RewriteEngine on

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /([^\ ]+)\.php
RewriteRule ^/?(.*)\.php$ /$1 [L,R=301]

RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^/?(.*)$ /$1.php [L]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM