Add or remove www from a domain


When you fully host your domain, you have the option to add the ‘www’ subdomain in front of it, leave it off entirely, or allow both options. For example:


While some people prefer to not use "www" in their website URL, some prefer that it always be there. Either way, it can sometimes be useful to have a single canonical name by which your site can be accessed. This article details how to do both.

Adding or removing "www" using an .htaccess file

You can add or remove 'www' using an .htaccess file. This involves creating and editing this file on your web server. View the following articles for information on creating or editing this file:

Removing "www" through an .htaccess file

To automatically remove the www from the beginning of your domain, add the following lines to your .htaccess file. If you don't have that file, create it in a text editor and then upload it to your root directory:

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

Forcing the ‘www’ subdomain in an .htaccess file

To force the use of "www" when viewers are reading your site, add the following lines to your .htaccess file:

RewriteEngine On
RewriteCond %{HTTP_HOST}  !^www\.example\.com$ [NC]
RewriteRule ^(.*)$1 [L,R]

If someone types in, the URL now change to

Adding or removing "www" in WordPress

It is not necessary to modify the .htaccess file to handle how 'www' appears in the URL. Instead, you can modify it within WordPress based on the URL you set up there, as WordPress makes .htaccess modifications on its own.

See the following article for more information on how to modify a WordPress site URL:

When adding or removing "www" breaks WordPress

WordPress is unique in that it requires the URL to either force www or remove www from the domain name. If your database is forcing www, but your panel is forcing its removal (or vice versa), you’ll see a redirect loop error that mentions that the page isn't redirecting properly.

To fix this error, make sure any customizations to your .htaccess file match what you selected within the WordPress configuration. View the Change WordPress Site URL article for instructions on how to update all URLs in your WordPress site.

Additional information

  • While most domains configure their main web server to answer to both forms, most do not bother with this type of redirection from one to the other. Ultimately, as long as the content served is the same, it doesn't usually matter what name is used to get to a given site.
  • One consideration when deciding whether to redirect to (or vice-versa) is that of Search Engine Optimization (SEO). Many search engines blacklist sites that "mirror" their site (have the same content at multiple URLs) under different domains and/or subdomains. Spiders may not blacklist for a "www" mirror, but better to play it safe by picking one and redirecting the other to it.

See also

Did this article answer your questions?

Article last updated PST.

Still not finding what you're looking for?