htaccess force HTTPS except one page
15,865
Using your example, you can use an out in your code.
RewriteEngine On
# Go to https if not on room.html
RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} !^/room.html$ [NC]
RewriteRule ^(.*)$ https://www.mycookiedomain.com/$1 [R,L]
# Go to http if you are on room.html
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/room.html$ [NC]
RewriteRule ^(.*)$ http://www.mycookiedomain.com/$1 [R,L]
You will likely have to tailor this a bit for your needs, but this example is at least close.
Related videos on Youtube
Author by
Vonwelzen
Updated on September 18, 2022Comments
-
Vonwelzen over 1 year
This is my current .htaccess file:
RewriteEngine On ErrorDocument 404 /404.html # 1 RewriteRule ^extra/([0-9]+)/(.*).html?$ pages.php?do=view&id=$1 RewriteRule ^special-bonus/([0-9]+)/(.*).html?$ pages.php?do=bonus&id=$1 RewriteRule ^thankyou/(.*).html?$ static.php?do=thankyou&prod=$1 # 2 RewriteRule ^list.html pages.php?do=list RewriteRule ^about.html static.php?do=about # 3 RewriteRule ^404.html static.php?do=404 RewriteRule ^room.html room.php # 4 RewriteRule ^sitemap.xml sitemap.php
I would like to force HTTPS (SSL) on every page except room.html. How can I do that? I am using Apache HTTP Server (ver 2.2.x).
To force HTTPS on every page I was using:
RewriteEngine On RewriteCond %{SERVER_PORT} 80 RewriteRule ^(.*)$ https://www.mycookiedomain.com/$1 [R,L]
It was working great but now I have to make change so it works on every page except room.html and I have no idea how to do that.
-
MrWhite about 9 yearsIs the temporary redirect (
R
) intentional? It would be more usual to have a permanent redirect (R=301
) for http to https redirection. -
Chris over 7 years@Martijn There are use cases. My current use: a site for a radio station, their online audio stream is not offered on https. Mobile listeners aren't able to stream it when the page is served with mixed content. So, I need to exclude that url, which opens in a popup.
-
Martijn over 7 yearsWhile it depends on the capacity of the radiostation, your effort should not go to making this one page https, it should be towards making the stream https. I get that there isn´t always budget for it, but it still is better to https.
-
Arne Kröger about 7 yearsI'm voting to close this question as off-topic because server configuration is off topic here and should be asked on serverfault.com
-
-
Martijn about 9 yearsI've added a reverse in case you end up on room.html, to turn it off again :)
-
closetnoc about 9 years@Martijn THANKS!! Oddly I do something like this and missed the fact you pointed out. I am glad you caught it!
-
Mustafa Al-Salhi over 5 years@closetnoc : I just copy past this code to redirect /firmwire to http instead of https. But aplombtechbd.com/firmware redirect to aplombtechbd.com/index.php. whats problem is going on?