www and non-www recommendations

Should we use www in front of our domains, or is non-www better? This article can hopefully help you decide.

1481 views
d

By. Jacob

Jacob Kristensen (Turbulentarius) is a Web Developer based in Denmark. He is currently pursuing a Bachelor's degree in Web Development at Zealand, focusing on learning React and refining his existing skills.

Edited: 2025-08-29 13:36

www to non-www, redirect

The www part of a URL is simply a subdomain. It stands for World Wide Web and is an optional part of server configuration. Many websites no longer use it, as it is often considered unnecessary.

Websites that do not use the www subdomain typically redirect it to the cleaner example.com version of their site. This is partly because some users still type "www" when visiting a website, and without a redirect, those users might encounter a 404 Not Found error.

The www subdomain has historically been used alongside other subdomains like the pop or imap subdomains for mail servers, and the ftp subdomain for FTP services. Administrators would point each of these subdomains to its corresponding service. While this isn’t usually relevant to end users, some companies adopted the www prefix in their marketing.

Recommendation

It is recommended that web developers redirect users to either the www or non-www version of their site — whichever they choose. The non-www version is generally preferred, as "www" adds no real value to users and requires extra typing.

Under some circumstances, the www subdomain is used to more clearly separate and isolate services, especially to avoid unintentionally sending cookies with HTTP requests for subdomains. E.g. When storing images on a subdomain like images.example.com subdomain, it would be redundant and wasteful to include cookies on every HTTP request.

Although it is possible to avoid the problem by using the proper syntax when assigning cookies, some code or JavaScript outside of your control might still assign cookies incorrectly, causing cookies to become "globally" available on all your subdomains. To avoid dealing with this, you could just host your site on the www subdomain. I'd personally still use the bare domain, and possibly opt for hosting images on another domain entirely, if this becomes a problem.

Redirecting your www subdomain

Redirecting the www subdomain can be done in several ways. One method is to use an .htaccess file; another is to configure your CMS to handle the redirect. However, not all CMS platforms support this out of the box. You might need to search for a plugin that enables it.

When using an .htaccess file to perform the redirect, you only need to create a file called .htaccess in a text editor and place it in your server root. Then, include the following content in the file:

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

Note: Replace example.com with your own domain name.

Tell us what you think:

  1. An in-dept look at the use of headings (h1-h6) and sections in HTML pages.
  2. Pagination can be a confusing thing to get right both practically and programmatically. I have put a lot of thought into this subject, and here I am giving you a few of the ideas I have been working with.
  3. The best way to deal with a trailing question mark is probably just to make it a bad request, because it is a very odd thing to find in a request URL.
  4. How to optimize image-loading and automatically include width and height attributes on img elements with PHP.
  5. HTTP headers are not case-sensitive, so we are free to convert them to all-lowercase in our applications.

More in: Web development