htaccess – HTTPS and non-WWW

By | 2019-01-03

Useful rewrite rule to keep things consistent. Enforce HTTPS and use non-WWW.

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