How to Force www and non-www on Your Domain with .htaccess Carrie SmahaUpdated on July 28, 2026 3 Minute 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. How to Force www on Your Domain A search engine such as Google interprets example.com and www.example.com as essentially two separate websites. It is recommended that users pick one version they’d like search engines to display. By using a 301 redirect, users can specify which domain name is displayed on their site. If you have a number of links on the web where people are linking to your site as example.com, but you would prefer your visitors end up at www.example.com instead, you can force this version of your domain with these rules: RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L]RewriteEngine On RewriteCond %{HTTP_HOST} ^example.com [NC] RewriteRule ^(.*)$ https://www.example.com/$1 [R=301,L] How to Force Non-www on Your Domain If you have a lot of links on the web where people are linking to your site as www.example.com, but you would prefer your visitors end up at example.com instead, you can force this version of your domain with these rules: RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example.com [NC] RewriteRule ^(.*)$ https://example.com/$1 [R=301,L]RewriteEngine On RewriteCond %{HTTP_HOST} ^www\.example.com [NC] RewriteRule ^(.*)$ https://example.com/$1 [R=301,L] 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. Summarize and Research with AIShare on Social Media Carrie Smaha Senior Manager Marketing Operations Carrie Smaha is a digital strategy, web development, and SEO leader with 20 years of experience. She built her foundation in fast-paced agency environments before moving in-house to InMotion Hosting, where she leads go-to-market programs, agency initiatives, and technical product marketing that connects product capability to real customer decisions. More Articles by Carrie Related Articles How to Upload Large Files Without FTP Timeouts eCommerce – Setup your Merchant Account Gateway How to Zip and Unzip Files on Windows 11 and Windows 10 How to Transfer and Backup Website Files with Rsync .htaccess File Reference List: Rules, Fixes, and Uses How to Force a File Download With .htaccess Redirecting Visitors to an Under Construction Page How to Force www and non-www on Your Domain with .htaccess How to Use the .htaccess File Domain Resolves to Server Default Page