Solved

SSL rewrite rule

Posted on 2006-11-27
6
646 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
Comment Utility
What exactly is the problem that occurs? Does anything happen, or does an error message appear?
0
 

Author Comment

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

Accepted Solution

by:
caterham_www earned 250 total points
Comment Utility
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
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 

Author Comment

by:evco
Comment Utility
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
Comment Utility
Wait, it works.

:)
0
 

Author Comment

by:evco
Comment Utility
Err, forgot to remove the .htaccess in the subfolder.

Thanks, caterham_www.
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Suggested Solutions

As Wikipedia explains 'robots.txt' as -- the robot exclusion standard, also known as the Robots Exclusion Protocol or robots.txt protocol, is a convention to prevent cooperating web spiders and other web robots from accessing all or part of a websit…
Over the last year I have answered a couple of basic URL rewriting questions several times so I thought I might as well have a stab at: explaining the basics, providing a few useful links and consolidating some of the most common queries into a sing…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

763 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now