Solved

SSL rewrite rule

Posted on 2006-11-27
6
652 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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Hosting a website using port 443 SSL CA using Wampserver 2 How to: 6 71
Redirect URL's containing question marks 5 91
htaccess file 3 92
setup wamp server for first time 2 96
Introduction As you’re probably aware the HTTP protocol offers basic / weak authentication, which in combination with the relevant configuration on your web server, provides the ability to password protect all or part of your host.  If you were not…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
Attackers love to prey on accounts that have privileges. Reducing privileged accounts and protecting privileged accounts therefore is paramount. Users, groups, and service accounts need to be protected to help protect the entire Active Directory …

679 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