bambinou1980 Posted September 2, 2015 Share Posted September 2, 2015 Hello, Could anyone tell me how I can force https on my whole website but not on a single folder or url. At the moment I have this code: RewriteEngine OnRewriteCond %{HTTP_HOST} ^thatmysite\.com [NC]RewriteCond %{SERVER_PORT} 80RewriteRule ^(.*)$ https://thatmysite.com/$1 [R,L] But if I add this second code in the root htaccess to remove https from the /thatsite.com/printing folder, I get a redirect loop because I am forcing on the code http to https and not https to http... RewriteCond %{HTTP:X-Forwarded-SSL} !onRewriteCond %{REQUEST_URI} ^\/(printing)RewriteRule (.*) https://%{HTTP_HOST}/$1 [L,R=301]RewriteCond %{HTTP:X-Forwarded-SSL} =onRewriteCond %{REQUEST_URI} !^\/(printing)RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301] Do you know a way around this please? I have been looking all over the internet and cannot find a single good answer. Thank you, Ben Quote Link to comment https://forums.phpfreaks.com/topic/298029-forcing-whole-website-to-https-but-not-one-url/ Share on other sites More sharing options...
scootstah Posted September 2, 2015 Share Posted September 2, 2015 The first question is, why do you want to do that? What's wrong with leaving HTTPS on for that folder? If you put your directory-excluding rewrite before the other one, with [L] flag, then it should not execute further rewrites if that one matches. Quote Link to comment https://forums.phpfreaks.com/topic/298029-forcing-whole-website-to-https-but-not-one-url/#findComment-1520152 Share on other sites More sharing options...
bambinou1980 Posted September 2, 2015 Author Share Posted September 2, 2015 Someone just gave me a beautiful solution in another forum: RewriteEngine On RewriteCond %{HTTPS} offRewriteCond %{THE_REQUEST} !/printing [NC]RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] RewriteCond %{HTTPS} onRewriteCond %{THE_REQUEST} /printing [NC]RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] By using this fantastic piece of code I can go on my website and have https all over but not in the folder /printing, just tired it and it works very well. Now it might sounds crazy to you but I have a good reason for this. I have multiple printers which are using 2g communications to communicate with my php order page and php callback page. The problem with those printers is that they do not work over https(got the message from the manufacturer today s I just could not get them to grab the files in https) and they have told me to force this specific url to http. Now security wise, there are no problem at all because this folder will not be accessible to users and will only be used for printer communications, no login there. Hope you understand now why I needed this so much. Quote Link to comment https://forums.phpfreaks.com/topic/298029-forcing-whole-website-to-https-but-not-one-url/#findComment-1520154 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.