Force www in .htaccess Updated on May 2, 2022 by InMotion Hosting Contributor 1 Minutes, 38 Seconds to Read Many customers at some point request to either force www or non-www version of their site to display in their visitor’s browser. For example, you can have www.example.com or simply example.com display in an address bar. While this difference won’t affect how visitors find your site, it can be a matter of aesthetic preference. This article will guide you through how to force www or non-www in your .htaccess file. You can access the .htaccess file through the cPanel File Manager. Force www or non-www in your .htaccess file in cPanel First, log into your cPanel.Once logged into cPanel, Find the Files category and click on the File Manager icon. Next, click Settings at the top right corner.In the Settings Menu, choose the document root (or folder) for the domain you are working with and be sure the checkbox next to Show Hidden Files is checked. Click the Save button. Look for the .htaccess file and right click on it. This brings up a menu. Find and click on the Edit option. You are now in the text editor. Place either selection of code in the file and click on the Save Changes button at the top right corner of the screen. Be sure to replace ‘example.com‘ with your actual domain name. NOTE: do not place both selections of code in the file as it will cause an error. Below are examples of code that you can use to implement the desired change to the website. Force www #Force www: RewriteEngine on RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC] Force non-www #Force non-www: RewriteEngine on RewriteCond %{HTTP_HOST} ^www.example.com [NC] RewriteRule ^(.*)$ https://example.com/$1 [L,R=301] Congratulations, you have successfully forced www or non-www! Now when you type in your domain name with either www in front or not, it should display as you have set it in the .htaccess file. Trust your business to an industry leader in fast and reliable website hosting solutions. InMotion Hosting offers secure web hosting with 99.99% uptime, 24/7 expert human support, and 100% money-back guarantee. Share this Article InMotion Hosting Contributor Content Writer InMotion Hosting contributors are highly knowledgeable individuals who create relevant content on new trends and troubleshooting techniques to help you achieve your online goals! More Articles by InMotion Hosting Related Articles How to Fix the “550 No Such User Here” Email Error What is Node.js? How to Deploy Websites Generated by AI Builders on Your Server How to Use robots.txt Disallow to Block Crawlers and Protect Site Performance Content Security Policy (CSP) Headers – Complete Reference Guide Troubleshooting SSL Connection Errors: How to Fix HTTPS Issues How to Check and Repair a Database in phpMyAdmin 21 Reasons Your Website is Slow and How to Speed it Up Website Transfer Resources Ensure a Successful Website Transfer