Redirecting between www and non-www URLs is an important part of managing a website. It ensures a consistent experience for users and helps with search engine rankings.
As a website owner, you may wonder if choosing www or non-www is just a personal preference.
While a non-www domain is shorter and easier to remember, it has some drawbacks. A www domain can prevent issues like split page rankings, broken inbound links, and duplicate content in search engines. This helps improve your website’s SEO.
If your site uses a non-www URL, redirecting it to www might seem difficult, but it's actually a simple process.
Why Redirect Non-www URLs to www?
Using a non-www domain has some downsides, such as limited control over traffic and cookies.
Non-www domains don’t support CNAME records, meaning you can’t redirect traffic to another server if yours is overloaded. This can lead to website downtime, affecting both user experience and SEO.
Search engines treat https://www.yourdomain.com and http://yourdomain.com as separate websites, which can split rankings and require different SEO strategies.
Additionally, a non-www domain doesn’t allow you to set up a cookie-free subdomain unless you create a separate domain for static content.
Fortunately, you can easily fix these issues by redirecting non-www URLs to www using the .htaccess file in cPanel.
How to Redirect a Non-www URL to a www URL Using .htaccess?
Follow these steps to redirect non-www URLs to www using the .htaccess file.
Step 1: Log in to cPanel.
Step 2: Navigate to the File Manager under the Files section.
Step 3: Open the public_html folder (or the root folder where your website is stored).
Step 4: Find the .htaccess file, right-click on it, and choose Edit.
If you can’t see the file, click Settings (top-right corner), check Show Hidden Files (dotfiles), and click the save button.
Step 5: Insert the following code into the .htaccess file and save the changes:
# Redirect non-www to www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^accucloudsupport\.com [NC]
RewriteRule ^(.*)$ https://www.accucloudsupport/$1 [L,R=301]
Understanding the Code
RewriteEngine On -> Activates the rewrite feature.
RewriteCond %{HTTP_HOST} ^accucloudsupport\.com [NC] -> Applies the rule when the domain is accessed without "www".
RewriteRule ^(.*)$ https://www.accucloudsupport.com/$1 [L,R=301] -> Redirects to the www version with a 301 permanent redirect.
R=301 -> Tells search engines this is a permanent redirect (good for SEO).
L -> Stops further processing once this rule is applied.
If Your Site Uses HTTPS
Make sure your redirect uses https:// instead of http://, like this:
For WordPress Users
WordPress has its own URL handling, so add the following extra rule after RewriteEngine On to avoid conflicts:
Best Practices
Backup your .htaccess file before making changes in case something goes wrong.
Update internal links to use the same URL format (either www or non-www) to keep consistency and avoid unnecessary redirects.
Notify search engines of your preferred domain using Google Search Console and Bing Webmaster Tools.
How to Redirect www to Non-www URLs Using .htaccess?
A www URL allows better cookie control, which can reduce HTTP requests and improve website performance. However, if you prefer a non-www URL, follow these steps to set up a redirect using .htaccess.
Steps to Redirect www to Non-www
Step 1: Log in to cPanel
Step 2: Go to the Files section and click File Manager.
Step 3: Open the public_html folder (or the root folder where your website files are stored).
Step 4: Find the .htaccess file, right-click it, and choose Edit.
Step 5: Insert the following code into the .htaccess file and save the changes:
# Redirect www to non-www
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [L,R=301]
RewriteEngine On -> Activates the rewrite function.
RewriteCond %{HTTP_HOST} ^www\.(.*)$ [NC] -> Applies the rule when the website is accessed with "www".
RewriteRule ^(.*)$ https://%1/$1 [L,R=301] -> Redirects to the non-www version with a 301 permanent redirect.
Step 6: After saving the .htaccess file, browse the website or domain in the browser and check the result. You can see that the website www.accucloudsupport redirects to accucloudsupport.com (non-www).
Alternative Solution:
Using Redirects in cPanel
The Redirects tool in cPanel allows you to send visitors from one URL to another. This is useful when you have a long URL and want to create a shorter, easier-to-remember link that leads to the same page.
You can also use redirects to protect sensitive customer data. For example, payment services like Stripe provide secure links for transactions, so your website does not have to store credit card details.
Important Notes:
- You cannot edit a redirect. To make changes, you must delete and then recreate it.
- To automatically redirect visitors from HTTP to HTTPS, use the Force HTTPS Redirect option in cPanel under Domains.
Follow these steps to set up a redirect:
Step 1: Log into cPanel.
Step 2: In the Domains section, click on Redirects.
Step 3: In the Redirects window, choose a Redirect Type
Permanent (301) -> Tells browsers to remember the new URL.
Temporary (302) -> Redirects without updating browser records.
Select a Domain
- Choose the domain you want to redirect.
- Or select All Public Domains to apply the redirect to all domains in your cPanel account.
Enter the Redirect Details
- In the first box, enter the URL path you want to redirect. (e.g., directory/file.html if redirecting http://accucloudsupport.com/directory/file.html.)
- In the Redirects to box, enter the destination URL (e.g., https://accucloudsupport.com).
Choose a www. Redirection Option:
- Only redirect with www. -> Redirects only when users type www. before the domain.
- Redirect with or without www. -> Redirects all visitors, whether they use www. or not.
- Do not redirect www. -> Users who type www. will not be redirected.
(Optional) Enable Wild Card Redirect
- If enabled, all files in the old domain will redirect to the same file in the new domain.
- Example: http://oldsite.com/pic.jpg will redirect to http://newsite.com/pic.jpg.
Step 4: Click Add to apply the redirect.
To test, check the Current Redirects table and click the link under the Directory column.
Conclusion
People often skip "www" when typing a website address. While this usually doesn’t cause problems since they still reach your site, it’s better to set up a redirect to the www version.
This helps improve your website’s performance and SEO.
Although it might seem technical, setting up the redirect is quick and takes just a minute or two.