Solved

SSL rewrite rule

Posted on 2006-11-27
6
650 Views
Last Modified: 2010-03-04
Hi,

I'd like to force https for a single page on my website (order_form.php). However, order_form.php is in two locations on my site:
/order_form.php
AND
/subfolder/order_form.php

****************** contents of .htaccess file in the root folder (works fine): ******************
Options +FollowSymlinks
RewriteEngine On

# non-www to www
RewriteCond %{http_host} ^domain.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,nc]

# https to http for all other pages
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/order_form.php
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# http to https for order form
RewriteCond %{HTTPS} !=on
RewriteRule ^order_form.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

*************** and for my .htaccess in the subfolder (doesn't work for http to https): ******************
Options +FollowSymlinks
RewriteEngine On

# https to http for all other pages
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} !^/subfolder/order_form.php
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# http to https for order form
RewriteCond %{HTTPS} !=on
RewriteRule ^subfolder/order_form.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

What I cannot get working is the rewrite rule for http to https for /subfolder/order_form.php

I'm not sure if I even need a second .htaccess in /subfolder. I assume it could all be done in the .htaccess file within the root but I've tried unsuccesfully to get it working for both order_form.php pages.

Thank you.
0
Comment
Question by:evco
  • 4
6 Comments
 
LVL 16

Expert Comment

by:HackneyCab
ID: 18025097
What exactly is the problem that occurs? Does anything happen, or does an error message appear?
0
 

Author Comment

by:evco
ID: 18025184
Sorry, about that...nothing happens, no redirect to http.
0
 
LVL 27

Accepted Solution

by:
caterham_www earned 250 total points
ID: 18030273
You might try in /.htaccess (root)

Options +FollowSymlinks
RewriteEngine On

# non-www to www
RewriteCond %{http_host} ^domain\.com [nc]
RewriteRule ^(.*)$ http://www.domain.com/$1 [r=301,L]

# https to http for all other pages
RewriteCond %{HTTPS} =on
RewriteRule !^(subfolder/)?order_form\.php$ http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

# http to https for order form
RewriteCond %{HTTPS} !=on
RewriteRule ^(subfolder/)?order_form\.php$ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
0
Connect further...control easier

With the ATEN CE624, you can now enjoy a high-quality visual experience powered by HDBaseT technology and the convenience of a single Cat6 cable to transmit uncompressed video with zero latency and multi-streaming for dual-view applications where remote access is required.

 

Author Comment

by:evco
ID: 18034379
I copy and pasted your exact code (made the appropriate changes to the domain name and subfolder name :))

Ended up with the same result. Everything works except for the http to https redirect on /subfolder/order_form.php

What I don't get is that the https to http redirect works fine for everything....?
0
 

Author Comment

by:evco
ID: 18034409
Wait, it works.

:)
0
 

Author Comment

by:evco
ID: 18034415
Err, forgot to remove the .htaccess in the subfolder.

Thanks, caterham_www.
0

Featured Post

Three Reasons Why Backup is Strategic

Backup is strategic to your business because your data is strategic to your business. Without backup, your business will fail. This white paper explains why it is vital for you to design and immediately execute a backup strategy to protect 100 percent of your data.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It is possible to boost certain documents at query time in Solr. Query time boosting can be a powerful resource for finding the most relevant and "best" content. Of course the more information you index, the more fields you will be able to use for y…
In Solr 4.0 it is possible to atomically (or partially) update individual fields in a document. This article will show the operations possible for atomic updating as well as setting up your Solr instance to be able to perform the actions. One major …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question