I know this topic has come up a lot in the past, but I can’t find a solution that works.
I have installed EE in a sub-directory on the domain /database as I’m building a database tool separate from their website.
How do I force everything in this directory to use https:// with the .htaccess file, as well as removing the index.php from the URL?
Thanks a lot.
This is what I normally use, replace example.com with your domain name:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force https
RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [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]
</IfModule>
I think I have stumbled across the solution - although I’m not sure if it’s wholly correct.
Suggestions welcome anyone in the know. 😊
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
# Force https
RewriteCond %{ENV:HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
# Directs all EE web requests through the site index file
RewriteCond $1 !\.(gif|jpe?g|png|htm|html)$ [NC] # Show these file types without going through Expression Engine first
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /database/index.php?/$1 [L]
</IfModule>
And here’s a very similar version of the same code, which is working on another site of mine:
#non-www to www
RewriteCond %{HTTP_HOST} !^www\.domainname\.co.uk$
RewriteRule (.*) https://www.domainname.co.uk/$1 [R=301,L]
# Force HTTPS
RewriteCond %{HTTPS} !=on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
# Removes index.php from ExpressionEngine URLs
RewriteCond %{THE_REQUEST} ^GET.*index\.php [NC]
RewriteCond %{REQUEST_URI} !/system/.* [NC]
RewriteRule (.*?)index\.php/*(.*) /$1$2 [R=301,NE,L]
And for the record, here’s another solution which seems to work on another site I’ve been struggling with (thanks to EllisLab for help):
RewriteCond %{ENV:HTTPS} !on [NC]
RewriteRule ^(.*)$ https://www.domainname.com/$1 [R,L]
RewriteCond %{ENV:HTTPS} on [NC]
RewriteCond %{HTTP_HOST} ^domainname\.com$ [NC]
RewriteRule ^(.*)$ https://www.domainname.com/$1 [R,L]
Ahhhhh ‘joy’ of htaccess and Redirects!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.