简体   繁体   中英

htaccess - do not rewrite URL if POST data

I have read quite many responses about htaccess but it is still so confusing to me. I have the following rule in my .htaccess file, basically removing the .php extension from the files and resolving the extensionless URL's:

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 eg contact_form.php (that handles processing of the form data from a form in HTML), it is being rewritten to contact_form and all the POST data is lost. I would like to achieve that when the request contains post data, the URL should not be redirected/rewritten. I have honestly no idea how the rewrite rule should look like. All help greatly appreciated!

You can insert this rule as first rule to ignore POST requests:

RewriteCond %{REQUEST_METHOD} POST
RewriteRule ^ - [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