I have some pages on my website that use http and other pages that use https. Now I want to use mod_rewrite to append www to all URLs whether they use http or https.
I have my current code in .htaccess:
RewriteCond %{HTTP_HOST} ^domain.com$ [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !index.php
RewriteCond $1 !^(index\.php|public|assets|robots\.txt)
RewriteRule ^(.*)$ ./index.php/$1 [L]
Please only focus on the first two lines as the rest are for other rewrite rules but I included it in case they were causing any errors for my first 2 lines.
Now this redirects all pages to http, but I want pages using https to be redirected to the right protocol. I tried the solution to a thread on StackOverflow (htaccess redirect for non-www both http and https) but it doesn't work for me.