1

I have a rule in my .htaccess to redirect all HTTP traffic to HTTPS, and I'm trying to exclude some specific URL from redirect, so I added the negation exclusion rule:

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/my_url
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

But this doesn't work, http://example.com/my_url redirects to front page example.com. Is it interfering with some other rules? All are standard Drupal core .htaccess.

1

You're right, there's interference with other Drupal rewrite rules. If you have clean URLs enabled, you're rewriting each request as an argument to index.php. Add an additional check to exclude this other rule.

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^/my_url
RewriteCond %{REQUEST_URI} !index.php
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
  • I've also tryied to add this RewriteCond %{REQUEST_URI} !index.php whith no luck, i also tryed to comment all this: RewriteRule ^ index.php [L] still no reaction/ – haver Apr 25 '16 at 7:40
  • As a general rule for testing redirects, you want to turn off all browser caching. Browsers cache HTTP 301/302 responses and it can confuse the state of your redirect testing. – Shawn Conn Apr 25 '16 at 19:34

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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