.htaccess Redirect Non Www


I have been using the following to rewrite any non www urls

#RewriteCond %{HTTP_HOST} ^example.com$

#RewriteRule (.*) https://www.example.com/$1 [R=301,L] 

It works for the standard redirect, but when I’m passing a more complex url with paramters like


It keeps removing the controller part and replacing it with index.php

I should mention I already have in my access file the code to remove the index.php script and this to reciredt to https:

<ifModule mod_rewrite.c>

# Turn on the engine:

RewriteEngine on

# Do not perform redirects for files and directories that exist:

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# For everything else, redirect to index.php:

RewriteRule . index.php

# From stackoverflow

RewriteCond %{HTTPS} !=on

RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


What am I doing wrong?



Not tested try this

RewriteCond %{HTTPS} off

RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

Thanks, doesn’t work though, just keeps the non ‘www’ part