PHP method=“post” stopped working after I added this .htaccess… Why?

后端 未结 2 706
孤独总比滥情好
孤独总比滥情好 2020-12-04 01:46

I\'ve added this .htaccess to remove file extension from the URL, so instead \"index.php\", it would show \"index\" only, all the times. But after I did it, my

相关标签:
2条回答
  • 2020-12-04 02:39

    This is happening because you are redirecting here:

    ## hide .php extension
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L,NC]
    

    When you redirect, the request BODY doesn't always get included, you can try adding an exception for POST:

    ## hide .php extension
    # To externally redirect /dir/foo.php to /dir/foo
    RewriteCond %{REQUEST_METHOD} !POST [NC]
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,}\s([^.]+)\.php [NC]
    RewriteRule ^ %1 [R,L,NC]
    
    0 讨论(0)
  • 2020-12-04 02:47

    Because the action of your form is pointing to /pwreset.php. When you try to go to that page (even via a form post), the htaccess will redirect you to /pwreset before any PHP code runs. A redirect will drop any POST data from the new request.

    You're going to have to change all those form actions to have the non-php version. As a short term fix, try excluding POST requests from your redirect rule

    RewriteCond %{REQUEST_METHOD} !POST

    0 讨论(0)
提交回复
热议问题