1

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.

Dave
  • 21
  • 4

3 Answers3

1

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.

Dave
  • 21
  • 4
0

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]

AliGibbs
  • 2,323
  • 21
  • 34
  • 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
0

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]
jon_d
  • 683
  • 4
  • 7
  • 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 http://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 http://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 !^http://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
  • It should be the first rule. The idea is to match first with a rewrite rule doing nothing except for stopping the rewriting process : `RewriteRule ^mydomain.com/(register|services/test).*$ - [L]` and then, doing the rewrite process as usual for all the URLs not having been caught by this rule. – jon_d Feb 15 '11 at 09:00