How do I redirect non-www to www? Print

  • 45

Title: How to Redirect Non-WWW to WWW in cPanel and Using .htaccess

Introduction:
In this updated article, we'll discuss how to redirect non-www (e.g., http://example.com) to www (e.g., http://www.example.com) in cPanel and by modifying the .htaccess file. This redirection helps to maintain consistency in your website's URL and can improve your search engine rankings.

Method 1: Redirect Non-WWW to WWW using cPanel

1. Log in to your cPanel account.
2. Navigate to the "Domains" section and click on the "Redirects" icon.
3. Choose "Permanent (301)" from the drop-down menu for the type of redirect.
4. Select the non-www domain (e.g., example.com) from the drop-down menu next to "http://(www)."
5. In the "Redirects to" field, enter the www version of your domain (e.g., http://www.example.com).
6. Ensure that the "Redirect with or without www?" option is set to "Only redirect with www."
7. Check the box for "Wildcard Redirect" if you want to redirect all subdomains as well.
8. Click the "Add" button to create the redirect.
9. Your non-www domain should now redirect to the www version.

Method 2: Redirect Non-WWW to WWW using .htaccess

If you prefer to edit the .htaccess file manually or don't have access to cPanel, follow these steps:

1. Access your website's root directory using an FTP client or your web host's file manager.
2. Locate the .htaccess file in the root directory. If it doesn't exist, create a new text file named ".htaccess" (without quotes).
3. Open the .htaccess file with a text editor.
4. Add the following code at the beginning of the file:

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

Replace "example.com" and "www.example.com" with your domain name.

5. Save the changes and upload the updated .htaccess file to your website's root directory.
6. Your non-www domain should now redirect to the www version.

Conclusion:

You've now successfully redirected your non-www domain to the www version using both cPanel and the .htaccess file. This will help maintain a consistent URL structure, enhance user experience, and improve search engine optimization.

If you require further assistance or have any questions, please visit our Knowledgebase or submit a support ticket  to get in touch with our team.


Was this answer helpful?

« Back