Random Linux

Linux, video games and web hosting

To force your domain name to use www, you are able to add the following code to the .htaccess file in the document root for that domain.

RewriteCond %{HTTP_HOST} ^domain.com [NC]
RewriteRule ^(.*)$ http://www.domain.com/$1 [L,R=301]

In the case of Randomlinux.com, if we wanted to make the URL www.randomlinux.com in the address bar all the time,  it would look like this:

RewriteCond %{HTTP_HOST} ^randomlinux.com [NC]
RewriteRule ^(.*)$ https://www.randomlinux.com/$1 [L,R=301]

Keep in mind that there are some cases that this will not work correctly.  For example, with WordPress, you cannot use this method.  With that, you have to force www using the administration panel or by modifying the database.

January 15th, 2011

Posted In: Uncategorized

Leave a Reply

Your email address will not be published. Required fields are marked *