Vincent's blog

.htaccess

I still dabble with the occasional .htaccess file, usually because I need to redirect to HTTPS and naked domain to www. I'm writing it down to avoid searching for it repeatedly.

# Redirect to https
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]

# Redirect to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301]