Apache force www subdomain

A redirect in an apache vhost to force the website to www.$domain.tld

<VirtualHost *:80>

...

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=302,L]


# test and reload
apachectl -t && apachectl -k graceful

Cloud & Open-Source magician 🧙‍♂️

I try to find the KISS in complex systems and share it with the world.

comments powered by Disqus