How do I add or remove www from my domain?

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

  • www.example.com
  • example.com

While some people prefer to not use "www" in their web site 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"

  1. Navigate to the (Panel > ‘Domains’ > ‘Manage Domains’) page.
  2. Click the Edit button to the right of your domain under the ‘Web Hosting’ column.
    The ‘Manage Domain’ page opens:
    01 Add a domain.png
  3. Select one of the three options next to ‘Do you want the www in your URL?’:
    • Leave it alone: Both www.example.com and example.com will work.
    • Add WWW: Forces all requests to add www (i.e., all requests to example.com go to www.example.com).
    • Remove WWW: Forces all requests to remove www (i.e., all requests to www.example.com go to example.com).

When 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 it’s removal (or vice versa), you’ll see a redirect loop error such as this:

01 Removing www from your domain.fw.png

The solution is to make sure the option in your DreamHost panel matches what you selected within the WordPress configuration. View the Change WordPress Site URL article for instructions on how to confirm which version is set within WordPress.

Using phpMyAdmin to update the URL in WordPress

  1. Go in to phpMyAdmin.
  2. Update the wp_options table and set siteurl and home values to http://example.com (without the www, and it should start redirecting properly).

Removing "www" through an .htaccess file

To automatically remove the www from the beginning of your domain, add the following mod_rewrite rule 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]
  1. Navigate to the (Panel > ‘Domains’ > ‘Manage Domains’) page.
  2. Click the Edit button to the right of your domain under the ‘Web Hosting’ column.
    01 Add a domain.png
  3. Select the radio button for ‘Add WWW’.
  4. Scroll down and click the blue Save changes button to save.

Within about 10 minutes, your site will redirect to the ‘www’ version of the URL.

Forcing the ‘www’ subdomain in an .htaccess file

To force the use of "www" when viewers are reading your site, you can use the following remove link mod_rewrite rule in your .htaccess file:

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

If someone types in example.com, the URL now change to www.example.com.

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 "example.com" to "www.example.com" (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