Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

SSL rewrite rule

Posted on 2006-11-27
6
Medium Priority
?
657 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 1000 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
NFR key for Veeam Agent for Linux

Veeam is happy to provide a free NFR license for one year.  It allows for the non‑production use and valid for five workstations and two servers. Veeam Agent for Linux is a simple backup tool for your Linux installations, both on‑premises and in the public cloud.

 

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

Question has a verified solution.

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

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…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
Suggested Courses
Course of the Month9 days, 18 hours left to enroll

610 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