Removing www tutorial. How to remove www from your website’s URL? Or add it. In this post, I’ll show you how you can enforce either a www or non-www URL by tweaking your .htaccess file.

Removing www From Site URL

Does use one or the other impact SEO?

You might be wondering if using one or the other will have an impact on your SEO. The answer is: no. It’s really just a matter of preference/esthetics. Just make sure you properly add the www and non-www domains in Google Search Console, as described here, to ensure Google can properly index your website.

Removing www From Site URL 2
Removing www From Site URL 2

 

Removing www from your domain name

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

If you prefer to market your website without the www prefix, you can add the following lines to your .htaccess file (Apache only):

Edit: As Thomas pointed out in the comments, it is not necessary to restart Apache after modifying the .htaccess file.

Note that Apache’s mod_rewrite module needs to be enabled. Otherwise, the above snippet won’t work.

Now, in Nginx this snippet is a bit different, but yields the exact same result when placed in the proper configuration file (which depends on your setup):

server {
 server_name www.example.com;
 return 301 http://example.com$request_uri;
}

Now just restart Nginx and you should be good to go!

Adding the www instead of removing it

To do the opposite of the previous section, add the following code to your .htaccess file:

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

And in Nginx, all it takes is this:

server {
 server_name example.com;
 return 301 http://www.example.com$request_uri;
}

That’s all there is to it!

But what about security?

Removing www From Site URL 1
Removing www From Site URL

 

As some of you pointed out in the comments (thank you for that!), there are some security concerns when you decide to use a non-www type URL.

If you run a variety of different services on subdomains, you run the risk of sharing cookies between your main, non-www homepage and said service. This could potentially be bad if certain sensitive data is being stored in cookies that you don’t want to be shared with third-parties.

There are a few other concerns with cookies and non-www style URLs, which you can read more about here
.

Share This Post