Reputation:
Sorry if this has been asked before, but I couldn't find it. I have a folder which when I visit loads in both HTTPS and HTTP.
I want all the files in that folder to load in HTTP except for one file. The file I need in in HTTPS is: login.php and this folder is called "forum". Also if it helps: All the files in the folder are *.php.
I was trying something along the lines of:
#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^/login.php$ - [L]
#RewriteCond %{SERVER_PORT} ^443$
#RewriteRule ^(/login.php) $ https://%{HTTP_HOST}/$1 [QSA,NC,R,L]
#RewriteCond %{SERVER_PORT} !^443$
#RewriteRule ^(.*)$ http://%{HTTP_HOST}/$1 [QSA,NC,R,L]
I'm a bit of an amateur when it comes to mod_rewrite so forgive me if the above is completely off. Also if you post a solution I would appreciate it if you post it with an explanation so I can actually LEARN how it works.
Thanks in advance! David
Upvotes: 0
Views: 3874
Reputation: 655239
Try these rules:
RewriteCond %{SERVER_PORT} !=443
RewriteRule ^login\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{SERVER_PORT} !=80
RewriteRule !^login\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
Upvotes: 0
Reputation: 24497
Give this a try:
Options +FollowSymLinks
RewriteEngine On
# port 443 traffic to http://, except login.php
RewriteCond %{SERVER_PORT} ^443$
RewriteCond %{REQUEST_URI} !^/login\.php$ [NC]
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# port 80 traffic for login.php to https://
RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} ^/login\.php$ [NC]
RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Upvotes: 1