Always add www. to url with htaccess

In this tutorial I described how you can remove the www. from an url. The opposite can be done just as easility.

With below code you can add www. as a standard subdomain when no subdomain is definded. In order to add www. as a default subdomain to the url you can add the following lines to your .htaccess file.



RewriteEngine On
RewriteCond %{HTTP_HOST} ^yourdomain.com$
RewriteRule (.*) http://www.yourdomain.com$1 [R=301]

This will redirect all http://yourdomain.com to http://www.yourdomain.com

Created on : 2017/01/20 - Last updated on : 2017/01/20

Back