0

I'm not all that familiar with htaccess and in attempting to do this myself I'm getting a too many redirects error so I thought I would go to the experts. I'm just looking for the right place within my htaccess file to force SSL on the entire site, while still removing www, removing index.php, etc (the usual fare for an EE install). My htaccess file currently looks like this:

<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} !/MySystemFolder/.*
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,L]

# Force SSL
# ------------------------------
# I'm guessing this is the position for the https rewrite rule
# but when I tried it, it resulted in a too many redirects error.

# 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 would greatly appreciate being pointed in the right direction.

1

this worked for me:

Options -Indexes

<IfModule mod_rewrite.c>
        RewriteEngine On
        RewriteBase /

        # Removes index.php from ExpressionEngine URLs
        RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
        RewriteCond %{REQUEST_URI} !/YOURSYSTEMFOLDER/.* [NC]
        RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]

        # Directs all EE web requests through the site index file
        RewriteCond %{REQUEST_FILENAME} !-f
        RewriteCond %{REQUEST_FILENAME} !-d
        RewriteRule ^(.*)$ /index.php?/$1 [L]

        # Force www
        Options +FollowSymlinks
        RewriteEngine on
        RewriteCond %{HTTP_HOST} ^YOURWEBSITE.com [NC]
        RewriteRule ^(.*)$ https://www.YOURWEBSITE.com/$1 [L,R=301,NC]
</IfModule>
| improve this answer | |
  • you can remove the "www." text in the last rewrite rule if you don't want to force www. – Marketing Alliance Feb 27 '18 at 14:32
  • Thanks for sharking that worked great for me. That killed two birds with one stone for me since I was going to look for the www rewriterule next. – Chris B Mar 27 '18 at 9:28

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.