0

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.

Community
  • 1
  • 1

1 Answers1

0

The answer you linked should work perfectly. If it isn't working, the HTTPS variable probably isn't set. This usually happens because you're not doing the HTTPS on your apache server. Perhaps you have a proxy that does it, or a load balancer? In that case you need to make sure the HTTPS variable gets set. Something like this often does the trick (the example works for amazon elastic load balancers):

SetEnvIf X-Forwarded-Proto https HTTPS=1
easel
  • 3,982
  • 26
  • 28