> ## Documentation Index
> Fetch the complete documentation index at: https://kb.hosting.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Adding or removing the www prefix in domain URLs

> Learn to manage the www prefix in your domain's URLs for seamless user redirection.

This article describes how to add or remove the *www* prefix in your domain's URLs. For example, if users type *[www.example.com](http://www.example.com)* in their browsers, you can automatically redirect them to *example.com*, or vice versa.

For Search Engine Optimization (SEO) purposes, it is preferable to have a website respond only to *[http://www.example.com](http://www.example.com)* or *[http://example.com](http://example.com)*, not both. Otherwise, search engines see duplicate content on the *www* and non-*www* domains, and may downgrade the site ranking.

## Adding the www prefix to domain URLs

You can automatically add the *www* prefix to your domain's URLs by using Apache rewrite rules in a custom *.htaccess* file. To do this, follow these steps:

1. Create an *.htaccess* file in your **public\_html** directory. If you already have an *.htaccess* file in the **public\_html** directory, you can modify it.
   > 📘 Note
   >
   > For more information about how to use *.htaccess* files, please see [this article](/docs/using-htaccess-files).

2. Copy and paste the following lines of text into the *.htaccess* file:

```
## Add www to any URLs that do not have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
```

3. Save the *.htaccess* file.

4. To test the configuration, use your web browser to visit *[http://example.com](http://example.com)*, where *example.com* represents your domain name. The browser should be redirected to *[http://www.example.com](http://www.example.com)*.

## Removing the www prefix from domain URLs

You can automatically remove the *www* prefix from your domain's URLs by using Apache rewrite rules in a custom *.htaccess* file. To do this, follow these steps:

1. Create an *.htaccess* file in your **public\_html** directory. If you already have an *.htaccess* file in the **public\_html** directory, you can modify it.
   > 📘 Note
   >
   > For more information about how to use *.htaccess* files, please see [this article](/docs/using-htaccess-files).

2. Copy and paste the following lines of text into the *.htaccess* file:

```
## Remove www from any URLs that have them:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.
RewriteRule ^(.*)$ http://example.com/$1 [R=301,L]
```

3. Replace *example.com* in the final line of text with your own domain name.

4. Save the *.htaccess* file.

5. To test the configuration, use your web browser to visit *[http://www.example.com](http://www.example.com)*, where *example.com* represents your domain name. The browser should be redirected to *[http://example.com](http://example.com)*.

## Related articles

* [Using www and non-www domains with an SSL certificate](/docs/using-www-and-non-www-domains-with-an-ssl-certificate)
