Rewrite index.html and index.php to root

Last modified: 
Thursday, 25. October 2018 - 3:59

#Rewrite index.html pages to the root domain
RewriteCond %{THE_REQUEST} ^.*/index\.html
RewriteRule ^(.*)index.html$ /$1 [R=301,L]

#Rewrite index.php to root
RewriteCond %{THE_REQUEST} ^.*/index\.php
RewriteRule ^(.*)index.php$ /$1 [R=301,L]

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

#Rewrite to https
RewriteCond %{HTTPS} !^on$
RewriteRule ^.*$ https://%{HTTP_HOST}%{REQUEST_URI}

#Rewrite to www
RewriteCond %{HTTP_HOST} !=""
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{HTTPS}s ^on(s)|
RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]