Htaccess - do not rewrite URL if POST data

I read quite a lot of htaccess reviews, but it still confuses me so much. I have the following rule in my .htaccess file, basically removing the .php extension from the files and resolving the URL without the extension:

RewriteEngine On

# Unless directory, remove trailing slash
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/]+)/$ http://www.example.com/$1 [R=301,L]

# Redirect external .php requests to extensionless url
RewriteCond %{THE_REQUEST} ^(.+)\.php([#?][^\ ]*)?\ HTTP/
RewriteRule ^(.+)\.php$ http://www.example.com/$1 [R=301,L]

# Resolve .php file for extensionless php urls
RewriteRule ^([^/.]+)$ $1.php [L]

However, when I want to contact, for example, contact_form.php (which handles the processing of form data from a form in HTML), it is written to contact_form and all POST data is lost. I would like to achieve this when the request contains data for publication, the URL should not be redirected / rewritten. I honestly have no idea what a rewrite rule should look like. All help is much appreciated!

+4
source share
1

, POST:

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [L]
+6

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


All Articles