UPDATED: mod_rewrite and POST method in PHP task, $ _POST is always empty

Im using mod_rewrite to display page addresses in a more readable way, instead

http://127.0.0.1/index.php?article=contact

I got

http://127.0.0.1/contact

when im submits the form, everything is processed by index.php, so I direct the form action to the current page displayed, but $ _POST is always empty, opening the form block looks like this

<form method="post" action="http://127.0.0.1/contact"> 

before I started mod_rewrite everything worked fine, but now mod_rewrite seems to be causing problems.

Please tell me what to change in PHP, Apache configuration files, or what else needs to be done to get $ _POST to work with rewrite endabled

Here are the rewriting rules that were requested

 RewriteEngine on #RewriteCond %{HTTP_HOST} !^www\. #RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L] RewriteRule \.(css|jpe?g|gif|png)$ - [L] RewriteCond %{REQUEST_URI} ^/[^\.]+[^/]$ RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L] RewriteRule ^([^/\.]+)/?$ index.php?page=$1 [L] RewriteRule ^([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&va=$2 [L] RewriteRule ^([^/\.]+)/([^/\.]+)/([^/\.]+)/?$ index.php?page=$1&va=$2&vb=$3 [L] 

Thanks in advance

Amir

+1
source share
1 answer

This rewrite rule does redirection, so the browser instead goes to this address with a GET request; therefore, POST data will always be empty.

 RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1/ [R=301,L] 
+2
source

Source: https://habr.com/ru/post/1397433/


All Articles