Solved

SSL rewrite rule

Posted on 2006-11-27
6
654 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 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
Efficient way to get backups off site to Azure

This user guide provides instructions on how to deploy and configure both a StoneFly Scale Out NAS Enterprise Cloud Drive virtual machine and Veeam Cloud Connect in the Microsoft Azure 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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

If you are a web developer, you would be aware of the <iframe> tag in HTML. The <iframe> stands for inline frame and is used to embed another document within the current HTML document. The embedded document could be even another website.
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…
There are cases when e.g. an IT administrator wants to have full access and view into selected mailboxes on Exchange server, directly from his own email account in Outlook or Outlook Web Access. This proves useful when for example administrator want…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

691 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