-4

htaccess rewrite rules make no sense to me! I'm simply trying to redirect the following:

http://www.domain.com
https://www.domain.com
http://domain.com

to

https://domain.com

Benjamin Allison
  • 2,134
  • 3
  • 30
  • 55
  • possible duplicate of [.htaccess redirect to https://www](http://stackoverflow.com/questions/14237805/htaccess-redirect-to-https-www) and http://stackoverflow.com/questions/13977851/htaccess-redirect-to-https-www?rq=1 – ceejayoz Mar 28 '14 at 02:19
  • Those both want to redirect to www. I want to redirect to the naked url. – Benjamin Allison Mar 28 '14 at 02:21
  • It should be extremely easy to figure out how to do the inverse. – ceejayoz Mar 28 '14 at 02:24
  • lol then why not do so and post an answer? One of the posts you're linking to doesn't even have an accepted answer... – Benjamin Allison Mar 28 '14 at 02:24
  • 1
    I'm not posting an answer because you didn't do the basic effort to find a solution. The "related" sidebar on your post shows a bunch of similar questions you could consult. For example, http://stackoverflow.com/questions/1478173/htaccess-redirect-www-to-non-www-with-ssl-https?rq=1 – ceejayoz Mar 28 '14 at 02:27

1 Answers1

0

You can use this rule in your root .htaccess file:

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ https://domain.com%{REQUEST_URI} [R=301,L,NE]
anubhava
  • 761,203
  • 64
  • 569
  • 643
  • I know I'm not the asker, but I tried that, it doesn't redirect `https://www.domain.com` to `https://domain.com` – Howli Mar 28 '14 at 08:36
  • This rule definitely does that if used at right place. There should not be any rule before this. – anubhava Mar 28 '14 at 11:26