Change from a secure connection to a non-secure connection using .htaccess
I am new to using .htaccess and I've done quite a bit of searching on the net, tried countless "solutions" to my problem, but none seem to do the trick.
Here's what I need: I want my contact.html page to downloaded using a secure connection (and thus, the f开发者_开发问答orm submission will send all the credentials safely encrypted, etc). I have accomplished this using .htaccess with no problems using code like:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]
Therefore, when a user navigates to that contact.html page, a secure connection is used. That works just fine. I want to use a secure connection to download ONLY that page, and of course to send user information encrypted back to the server. However, once the secure connection is established to fetch the contact.html file, all other files from that point on are downloaded via a secure connection. E.g., I navigate to the contact page, then jump (click a link) from there to the about.html page, the secure connection is still used. I have tried numerous different proposals to change protocols, from https to http, such as:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^contact\.html$
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
But none of them work. I don't fully understand all the capabilities (and limitations) of using .htaccess, so could someone tell me if what I'm aiming for can be accomplished using .htaccess, or do I need to seek alternatives?
Thanks for any help!
UPDATE 1
Here is the entire code of my root .htaccess file. NOTE: I modified the code since my previous post.
RewriteEngine On
Options FollowSymLinks
RewriteCond %{REQUEST_URI} !^/contact/contact\.html$
RewriteCond %{HTTPS} on
RewriteRule ^(.*) http://beta.runtimeriot.com/$1 [R=301,L]
RewriteCond %{HTTPS} off
RewriteRule ^(/contact/contact\.html)$ https://beta.runtimeriot.com/$1 [R=301,L]
I am actually surprised that your 1st rule works, as the REQUEST_URI variable usually contains the leading /, so your rule should be:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]
although I guess you actually mean:
RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} ^/contact/contact\.html$
RewriteRule ^(.*)$ https://beta.runtimeriot.com/contact/$1 [R=301,L]
or, for simplicity:
RewriteCond %{HTTPS} off
RewriteRule ^/contact/contact\.html https://beta.runtimeriot.com/$1 [R=301,L]
Your second rule looks functional, but it would probably create an infinte loop, as it is matched by /contact/contact.html too. Should be:
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/contact/contact\.html$
RewriteRule (.*) http://%{HTTP_HOST}$1 [R=301,L]
Finally, I believe your problem is that you're confused and the 1st rule is not working either (I actually tested http://beta.runtimeriot.com/contact.html and it didn't swap to https). Possible causes:
- Have you enabled the rewrite engine with
RewriteEngine on
? (see: http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriteengine) - Does the server-wide Apache configuration contain
AllowOverride FileInfo
orAllowOverride ALL
, so thatRewriteEngine on
will be acceptable in .htaccess files?
精彩评论