0

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!

2 Answers 2

1

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.

1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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