> ## Knowledge Base Index
> Fetch the complete knowledge base index at: https://help.ex2.com/sitemap.xml
> Use this file to discover available pages before exploring further.
> Pure-Markdown content can be obtained by appending a '.md' suffix to the content URLs listed in the sitemap (without the trailing slash).

# How to redirect non-www urls to www?

Redirecting non-www requests to the www version of your website [URL](https://help.ex2.com/en/article/what-is-a-url-1rlh9di/?bust=1784820887559) is good for SEO. Not only will this help you avoid duplicating content on Google, but it will also avoid splitting your inbound links on 2 different URLs. In this article, we will learn how to redirect non-www URLs to www URLs using the [.htaccess file](https://help.ex2.com/en/article/what-is-the-htaccess-file-and-what-is-it-used-for-1mgswq0/?bust=1784828396531) in your public_html folder.

# Here's how to redirect non-www urls to www

#### Editing the .htaccess file

To redirect a non-www url to www, we need to add a rule in the .htaccess file. You can do this via [FTP](https://help.ex2.com/en/article/what-is-the-ftp-protocol-jhosf3/?bust=1784817449554), [SSH](https://help.ex2.com/en/article/what-is-the-ssh-protocol-10ohmg0/?bust=1784819279302), or more simply via your cPanel control panel.

Follow the steps below to edit your .htaccess file from cPanel Ex2:

Before you start, you need to [log in to your cPanel account](https://help.ex2.com/en/article/how-to-log-in-to-my-cpanel-account-xyoqm0/?bust=1676305236426). 

1.  Go to the **Files** section and open **File Manager**.
2.  Navigate to the **public_html** directory
3.  Right-click on the **.htaccess** file and select **Edit**. The file may not be visible, if so, click "**Settings**" at the top right of your File Manager, then select "**Show hidden files**" then click "**Save**".
4.  If a screen appears asking you to confirm the encoding, choose utf-8 (if you are using a Western language) and click **EDIT**.
5.  Insert the following lines (Note : If **RewriteEngine** **On** is already registered on the file, do not rewrite) :

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

> **Warning !** Remember to change the code with your current domain name instead of **yourdomainname**.com. Once you're done, don't forget to save the changes.

**Congratulations**, you have successfully activated a **.htaccess** rule that will redirect all visitors from a non-www url to the www version of your website! It wasn't difficult at all, was it?

There you go ! By completing this tutorial, you have learned how to redirect non-www urls to www. Now when a person accesses http://yourdomain.com, they will be redirected to http://www.yourdomain.com.