title: Redirect www and non https to nonwww and https
body: <p>I have a bunch of different websites on my server and i'm currently using this redirect rule in my htaccess for all of them</p>
  
  <pre><code>RewriteCond %{HTTPS} off [OR]
  RewriteCond %{HTTP_HOST} ^www\. [NC]
  RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
  RewriteRule ^ https://%1%{REQUEST_URI} [L,NE,R=301]
  </code></pre>
  
  <p>the htacces files are exactly the same. but for some reason only some of the sites are redirecting www to nonwww and some aren't. Any reason this works for some sites and doesn't work for others?</p>
  
  <p>whats strange is that when i go to www.example.com it doesn't redirect. But when I click on a link on that page such as www.example.com/login. It then redirects the www to <a href="https://example.com/login" rel="nofollow noreferrer">https://example.com/login</a> even though the link is www.example.com/login</p>
  
  <p>EDIT: I use the codeigniter framework and have this rule above it to remove the index.php in the url</p>
  
  <pre><code>RewriteCond $1 !^(index\.php|assets|robots\.txt)
  RewriteRule ^(.*)$ /index.php/$1 [L]
  </code></pre>