Do I want www prefix in my domain URL?

Do I want www prefix in my domain URL?

Long story short, sometimes you may want to include www prefix into domain URL. If so here is how to do it using good old .htaccess file.
Same as before the method is simple, you download the .htaccess file from the root directory using FTP client of your choice, make a copy of it (just in case), and alter it using text editor.

1. Force www

Copy/paste the following code in your .htaccess file if you want to use the www prefix in your domain URL:


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

Please note: example.com should be replaced with your actual domain name.

2. Force non-www

Copy/paste the following code in your .htaccess file if you want to avoid www prefix in you domain URL:


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

Please note: example.com should be replaced with your actual domain name.

It’s important to be aware that if you don’t use a www (or some other subdomain) then all cookies will be submitted to every subdomain and you won’t be able to have a cookie-less subdomain for serving static content thus reducing the amount of data sent back and forth between the browser and the server. Something you might later come to regret.

Another thing to consider, make sure you’re setting the canonical name without the www in your pages, to avoid a possible duplicate content penalty. Also if you have absolute URLs in your links make sure they’re all non-www as well.

By janoshke

Web developer and IT consultant. Freelancer with full respect for OpenCart and WordPress. Gamer, (ex)drummer and parent.

Leave a Reply