Greetings,
I'm trying to force rewriting URLs that do not use the HTTPS protocol and do not have the www through mod_rewriter in htacess.
I'm using codeigniter, so I take the index.php.
<IfModule mod_rewrite.c>
RewriteEngine On
Options -Indexes
Options +FollowSymLinks -MultiViews
DirectoryIndex index.php
#Forçando HTTPS
RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} !^virtual.host(.*)$
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]
#Forçando www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
#Retirando index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L]
</IfModule>
The problem is that when I test without https or without the www, in some cases it is redirecting me to the index ( link ), in some cases it works correctly.
I have tried in many ways to get around but to no avail.