0

I have a .htaccess that's supposed to force connection using SSL. It works well on localhost, when I take it online I have all manner of errors. Here is my code.

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([a-zA-Z]*)/?$ goto.php?page=$1
ErrorDocument 404 PageNotFound
IndexIgnore *

RewriteRule ^(.*)$ https://example.com/$1 [R,L]

Where am I missing it please, thank you.

1
  • 1) What kind of errors (check Apache's error.log); 2) Of course you will have the redirect loop -- the very last line does exactly that. You better to explain what these rules supposed to do, especially the last one. Commented Sep 23, 2011 at 8:17

1 Answer 1

1

The problem is here:

RewriteRule ^(.*)$ https://example.com/$1 [R,L]

The ^(.*)$ matches everything so will keep matching even after it has redirected the user to https, thus the infinite loop.

So you need to make this rule only match when it is required, the folloing RewriteCond should cause the rule to only match whilst https is off, which should stop the infinite loop:

RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://example.com/$1 [R,L]
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.