Mobile app version of vmapp.org
Login or Join
Hamm4606531

: Htaccess force HTTPS except one page This is my current .htaccess file: RewriteEngine On ErrorDocument 404 /404.html # 1 RewriteRule ^extra/([0-9]+)/(.*).html?$ pages.php?do=view&id= RewriteRule ^special-bonus/([0-9]+)/(.*).html?$

@Hamm4606531

Posted in: #Apache #Htaccess #Https #Redirects

This is my current .htaccess file:

RewriteEngine On
ErrorDocument 404 /404.html
# 1
RewriteRule ^extra/([0-9]+)/(.*).html?$ pages.php?do=view&id=
RewriteRule ^special-bonus/([0-9]+)/(.*).html?$ pages.php?do=bonus&id=
RewriteRule ^thankyou/(.*).html?$ static.php?do=thankyou&prod=
# 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 ^(.*)$ www.mycookiedomain.com/ [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.

10.02% popularity Vote Up Vote Down


Login to follow query

More posts by @Hamm4606531

2 Comments

Sorted by latest first Latest Oldest Best

 

@Sent6035632

It doesn't get much simpler than this. You can use PHP files for error documents instead of HTML files, so one of your lines is not required. Also, I simplified and fixed the rewritecond and rewriterule. The only condition you really are checking is to see if connection is on standard HTTP port, and if it is, then replace the request to room.html with room.php on mycookiedomain.com, and because you're switching from HTTP to HTTP secure, you should use an actual redirect (status code 301) instead of the default 302.

Also, for best results, make sure all mentioned files as well as .htaccess is in the same folder.

ErrorDocument 404 static.php?do=404

RewriteEngine On
RewriteCond %{SERVER_PORT} 80
RewriteRule ^room.html$ www.mycookiedomain.com/room.php [R=301,L]

RewriteRule ^extra/([0-9]+)/(.*).html?$ pages.php?do=view&id=
RewriteRule ^special-bonus/([0-9]+)/(.*).html?$ pages.php?do=bonus&id=
RewriteRule ^thankyou/(.*).html?$ static.php?do=thankyou&prod=

RewriteRule ^list.html pages.php?do=list
RewriteRule ^about.html static.php?do=about

RewriteRule ^sitemap.xml sitemap.php

10% popularity Vote Up Vote Down


 

@Alves908

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 ^(.*)$ www.mycookiedomain.com/ [R,L]

# Go to http if you are on room.html
RewriteCond %{SERVER_PORT} !80
RewriteCond %{REQUEST_URI} ^/room.html$ [NC]
RewriteRule ^(.*)$ www.mycookiedomain.com/ [R,L]


You will likely have to tailor this a bit for your needs, but this example is at least close.

10% popularity Vote Up Vote Down


Back to top | Use Dark Theme