Tuesday, March 13, 2018

.htaccess - http:// to https:// Redirection with page reload in Apache 2 (HD Web Hosting)

I'm trying to check to see if the address accessed is using a secure connection when accessing a certain page, or not. If not, I want to redirect the traffic to the proper https:// address.



I have tried doing this in several ways in the .htaccess file.



I was able to rewrite http://foosite.com/contact.shtml and http://www.foosite.com/contact.shtml addresses as https://www.foosite.com/contact.shtml with:




RewriteEngine on
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (contact.*)
RewriteRule (.*) https ://www.foosite.com%{REQUEST_URI}


...but this only rewrites the URL, it does not reload the page, therefore there is no encryption and there is a warning/caution sign next to the HTTPS in the address bar (as there should be).



I need to reload that page so that the encryption is enforced.




Based on what I am looking at I was thinking something like:



RedirectCond %{HTTPS} off
RedirectCond %{REQUEST_URI} (contact.*)
Redirect 301 https ://www.foosite.com/contact.shtml


...but this is based purely on conjecture after looking at some posts in here and imagining what might work. Conjecture is not a good thing to count on, anyway. I don't even know if there is a RedirectCond tag.




So, as I am not familiar with .htaccess at all, just looking to secure a single form, what would work to redirect a page to the HTTPS address of it when it isn't loaded securely?

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...