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've got a directive set up in my htaccess to send all non-https traffic to https

RewriteCond %{SERVER_PORT} ^80$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

# These are used by the Zend Framework...
RewriteCond %{REQUEST_FILENAME} \.(js|css|gif|jpg|png|swf)$ [OR] 
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ index.php [NC,L]

I now need to add two exceptions to stop them being redirected to https - one for mydomain.com/register/ and one for mydomain.com/services/test/

Could anyone help me out?

Thanks.

share|improve this question

migrated from stackoverflow.com Feb 11 '11 at 16:36

This question came from our site for professional and enthusiast programmers.

3 Answers 3

up vote 1 down vote accepted

Ok, someone helped me to get it working using:

 RewriteEngine On

 RewriteCond %{SERVER_PORT} !^443$
 RewriteCond %{THE_REQUEST} !/services/test
 RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

 RewriteCond %{REQUEST_FILENAME} \.(js|css|gif|jpg|png|swf)$ [OR]
 RewriteCond %{REQUEST_FILENAME} -s [OR]
 RewriteCond %{REQUEST_FILENAME} -l [OR]
 RewriteCond %{REQUEST_FILENAME} -d
 RewriteRule ^.*$ - [NC,L]

 RewriteCond %{THE_REQUEST} /services/test
 RewriteRule ^.*$ index.php [NC,L]

 RewriteRule ^.*$ index.php [NC,L]

The Zend Framework rewrite rule was causing a problem, but it's working ok now.

share|improve this answer

RewriteCond %{SERVER_PORT} ^80$
RewriteCond %{REQUEST_URI} !^mydomain.com/register/$
RewriteCond %{REQUEST_URI} !^mydomain.com/services/test/$
RewriteRule .* https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

share|improve this answer
    
Thanks, but it's still redirecting everything to https. I've tried it with only the first condition (mydomain.com/register/), but no luck. –  Dave Feb 14 '11 at 10:35
    
The %{REQUEST_URI} variable does not contain the domain. The %{HTTP_HOST} variable does. –  Ladadadada Dec 23 '11 at 11:23

You could do the rewriting only if the URL do not match you two exceptions :

RewriteCond %{SERVER_PORT} ^80$
RewriteRule !^http://mydomain.com/(register|services/test).*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]
share|improve this answer
    
Thanks, but same problem; it's still redirecting everything to https. –  Dave Feb 14 '11 at 10:38
    
Then you have another RewriteRule before the one you modified or, most likely, the pattern for the two exceptions does not match. You can test if the pattern match by trying it in a different RewriteRule before the "https" one, redirecting to a totaly different place (like serverfault.com for example) –  jon_d Feb 14 '11 at 12:30
    
No, no other rewrite rules in the htaccess. It works when redirecting to serverfault.com, but not when using https://%{SERVER_NAME}%{REQUEST_URI} (it still sends everything to https) –  Dave Feb 14 '11 at 15:04
    
Can you try with a rewrite rule not rewriting anything and ending the rewriting process like RewriteRule mydomain.com/register/ - [L] before the "https" rewrite rule ? (in fact you could use the rewrite rule you tried on serverfault.com, replacing serverfault.com by - and adding [L] at the end) –  jon_d Feb 14 '11 at 15:53
    
Sorry, what should that go in before? (is it before RewriteRule !^mydomain.com/(register|services/test).*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L] )? - That's giving me an error that the page isn't redirecting properly in Firefox. (Thanks for your help with this by the way!) –  Dave Feb 14 '11 at 21:32

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.