0

This has been asked a million times, but I can't seem to find the right search terms. I would like to redirect all request URIs from:

to

The best answer I have found was:

RewriteEngine On 
RewriteCond %{HTTPS} off 
RewriteCond %{HTTP_HOST} ^(?:www\.)?(.*)$ [NC]
RewriteRule (.*) https://%1%{REQUEST_URI} [L,R=301]

But that gives me a redirect loop. Any ideas?

Leah
  • 335
  • 1
  • 3
  • 8
  • possible duplicate of [Generic htaccess redirect www to non-www](http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www) – Kiran RS Mar 31 '14 at 06:25

1 Answers1

0

This should work for you:

RewriteEngine On 

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [L,R=301,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • Unfortunately that results in a redirect loop. Also is there a way to make this work on multiple domains - we have a staging server too (eg: `https://stage.domain.com`) and it would be great if we could use the same code on both. – Leah Mar 31 '14 at 10:09