views:

11

answers:

2

I have the following problem:

  • If the url contains the keyword "formulario-" and it is a http connection, I want to redirect to the https version.
  • If the url doesn't contain the keyword "formulario-" and it is a https connection, I want to redirecto to http version.

I tried the following .htaccess but it doens't work properly:

RewriteEngine On

RewriteCond %{HTTPS} =on
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI}

RewriteCond %{HTTPS} !=on
RewriteRule ^formulario-(.*) http://%{HTTP_HOST}%{REQUEST_URI}

Thanks for your help!

+1  A: 

What exactly does not work?

One thing that comes to mind is: Try using the [L] flag for the first rule, so that apache stops to process the second rule, if the first rule applies.

I am not sure that's it though. You probably need some way to test whether the user was already redirected before.

maschka
+1  A: 

Untested, but the general idea is:

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule formulario- https://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !formulario-
RewriteRule .* http://%{HTTP_HOST}%{REQUEST_URI} [R,L,QSA]

The theory being you cannot negate a RewriteRule, but you can negate a RewriteCond.

Wrikken