Wednesday, November 15, 2017

mod rewrite - Redirect apache to http requests to https except for when request is a POST?



I have setup my apache2 configuration to redirect http requests to https. This works fine however I want to change it so that it only does this if the request is not a POST request.



Here is my current configuration:




RewriteEngine On




RewriteCond %{HTTPS} !=on



RewriteRule ^/?(.*) https:// %{SERVER_NAME}/$1 [R,L]




How can I change this configration so that it only redirects when the request is not a POST?


Answer



Add a new RewriteCond line:



RewriteEngine On

RewriteCond %{HTTPS} !=on
RewriteCond %{REQUEST_METHOD} !^POST$
RewriteRule ^/?(.*) https:// %{SERVER_NAME}/$1 [R,L]

No comments:

Post a Comment

linux - How to SSH to ec2 instance in VPC private subnet via NAT server

I have created a VPC in aws with a public subnet and a private subnet. The private subnet does not have direct access to external network. S...