0

I'm having some trouble with forcing https on a given template group. If I use the following, I get the "too many redirects" error. If I comment out my "force SSL" conditions, everything else works fine (removal of www, removal of index.php, etc.). Can anyone point out what's out of place here? This is for a site hosted with EngineHosting (if that plays any role here) and I am using the Charge add-on with "force SSL" turned on (which forces https:// on the post value on the module's generated form)

<IfModule mod_rewrite.c>

# Enable Rewrite Engine
# ------------------------------
RewriteEngine On
RewriteBase /

# Redirect www Requests
# ------------------------------
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ http://%1/$1 [R=301,L]

# Redirect index.php Requests
# ------------------------------
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{THE_REQUEST} !/my_system_folder/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

# Forse SSL on Donate Section Requests
# ------------------------------
RewriteCond %{HTTPS} off
RewriteCond $1 ^(donate) [NC]
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Standard ExpressionEngine Rewrite
# ------------------------------
RewriteCond $1 !\.(css|js|gif|jpe?g|png) [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /index.php/$1 [L]

</IfModule>

#add Expires
# ------------------------------
FileETag MTime Size
<IfModule mod_expires.c>
  <filesmatch "\.(jpg|png|css|js|jpeg|woff|ttf|svg|eot|gif)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</IfModule>

I just want to force SSL on any /donate URI.

0

Whilst not answering directly, I've always used force SSL module and it just works: http://devot-ee.com/add-ons/dm-force-ssl

| improve this answer | |
  • I tried using the add-on but it had no effect. I followed the install instructions - which were pretty simple - and it just didn't seem to do anything. – Jean St-Amand May 20 '14 at 19:30
0

I think I ended up hard coding the domain into the redirect. Everything else seemed to cause issues or not work 100% of the time.

# Remove www
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
  RewriteRule ^(.*)$ http://%1%{REQUEST_URI} [R=301,QSA,NC,L]
</IfModule>

# Always secure
<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteCond %{HTTPS} !=on
  RewriteRule (.*) https://domain.com%{REQUEST_URI}
</IfModule>

# Remove index.php
<IfModule mod_rewrite.c>
  RewriteCond $1 !\.(gif|jpe?g|png)$ [NC]
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ /index.php?/$1 [L]
</IfModule>
| improve this answer | |
0

The following code works great for me, and utitlizes a 301 redirect so that you can keep any existing pagerank for SEO! I add this before the code that removes index.php.

<IfModule mod_rewrite.c>

    RewriteEngine On

    #force SSL
    RewriteCond %{HTTPS} !=on
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

</IfModule>
| improve this answer | |
  • This code gives me "Error, to many redirects" – podarok Oct 20 '15 at 10:14
  • @podarok Do you have any other redirect scripts in place that may be conflicting? – Jon Horton Oct 21 '15 at 20:01
  • Yup, sorry about that There was a redirect handler added in HAProxy config in front of the apache. So nevermind my previous comment – podarok Oct 22 '15 at 12:01

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.