Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I have a site that is completely servered through ssl. I need to allow an external connection on a single page through http though.

Currently in my http.conf I have

<VirtualHost *:80>
..
Redirect permanent / https://www.mysite.com/
..
</VirtualHost>

I want to add an exception here for a certain page that I only want servered and never through a redirect if possible as http...

http://www.mysite.com/directory/page.php 

I tried adding the following but of course this by itself works just fine but in conjunction with what I have above it creates redirect loops.

<VirtualHost *:443>
..
RewriteEngine on
RewriteCond %{SERVER_PORT} ^443$
RewriteRule ^/directory/page$ http://www.mysite.com/directory/page.php [R=301,L]
..
</VirtualHost>
share|improve this question
    
I would check the ordering of the rules. If you have another redirect above it that is trying to make it go to https then you will loop. Step through the logic yourself line by line and see what you get. –  drinxy Feb 28 '13 at 1:59

2 Answers 2

Try this:

RewriteEngine on

RewriteCond %{HTTPS} on
RewriteRule ^/directory/page$ http://www.mysite.com/directory/page.php [R=301,L]

RewriteCond %{HTTPS} on
RewriteRule ^/directory/page.php  http://www.mysite.com/directory/page.php [R,L]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/directory/page.php
RewriteRule ^/(.*)  https://www.mysite.com/$1 [R,L]
share|improve this answer
    
With this if I browse to http://www.mysite.com/directory/page.php it takes me to index.php, if I browse to https://www.mysite.com/directory/page.php it stays a secure connection –  enfield Feb 28 '13 at 3:38
    
Made a couple edits to support this new requirement on forcing /directory/page.php to be non-ssl. On redirecting to the index, I'm not sure, maybe you have something else in your configuration? I suspect that /directory/page.php is not the real url so maybe you missed changing it somewhere? –  ETL Feb 28 '13 at 14:48
up vote 1 down vote accepted

Here is what finally worked:

# Force HTTPS for entire site
RewriteCond %{HTTPS} !=on
RewriteCond %{THE_REQUEST} !^[A-Z]+\s/directory/page.*$
RewriteRule ^(.*)$ https://www.mysite.com/$1 [R=301,L]

# Force HTTP for a given page
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} ^/directory/page.*$
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.