简体   繁体   中英

RewriteCond and RewriteRule can stop POST?

In my .htaccess I have these instructions:

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. No way, neither with php nor html nor ajax nor jquery. No POST values are passed. 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? My need is to externally redirect /dir/foo.php to /dir/foo and to internally redirect /dir/foo to /dir/foo.php.

your .htaccess should be like this

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

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]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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