How to Force www or Non-www in Your WordPress Site

Introduction

Many website owners often wonder whether to display their website with or without the “www” prefix. While this decision may not impact how visitors find your site, it can be a matter of personal preference or maintaining consistency. In this article, we will guide you through the process of forcing either the www or non-www version of your website using the .htaccess file in cPanel. By following these simple steps, you can ensure that your website always displays the desired format.

Step 1

Log into your cPanel To begin, log into your cPanel account using your credentials. This is typically provided by your web hosting provider. Once logged in, you will have access to various tools and settings to manage your website.

Step 2

Open the File Manager After accessing your cPanel, locate the “Files” category and click on the “File Manager” icon. This will open the File Manager interface, which allows you to navigate and modify your website’s files.

Step 3

Adjust File Manager Settings In the top right corner of the File Manager interface, you will find the “Settings” button. Click on it to open the Settings menu. Here, you need to choose the document root (or folder) for the specific domain you wish to work with. Make sure the checkbox next to “Show Hidden Files” is checked, as it will ensure the visibility of the .htaccess file. Once done, click the “Save” button to apply the changes.

Step 4

Locate and Edit the .htaccess File Now, navigate to the folder that contains your WordPress installation. Look for the .htaccess file, which is a configuration file used by the Apache web server. Right-click on the .htaccess file and select the “Edit” option from the menu that appears.

Step 5

Implement the Desired Change You are now in the text editor, where you can modify the .htaccess file. Choose the code snippet that corresponds to the version you want to force and paste it into the file.

Forcing www

#Force www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301,NC]

Forcing non-www

#Force non-www:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www.example.com [NC]
RewriteRule ^(.*)$ https://example.com/$1 [L,R=301]

Remember to replace ‘example.com’ with your actual domain name in both code snippets.

Step 6

Save Changes and Verify After pasting the desired code snippet, click on the “Save Changes” button at the top right corner of the screen. Your .htaccess file is now updated. To verify if the changes have taken effect, open a new browser tab and type in your domain name, both with and without the www prefix. Your website should now display as you have set it in the .htaccess file.

Conclusion

Congratulations! You have successfully forced either the www or non-www version of your WordPress website using the .htaccess file in cPanel. By following these simple steps, you can ensure that your website consistently displays the format you prefer. Remember, maintaining a uniform appearance can contribute to the overall aesthetic appeal of your website.

Experience unrivaled performance with our cutting-edge web solutions, leveraging industry-leading service providers and public/private cloud infrastructure. Propel your online presence to new heights with lightning-fast speeds and unbeatable scalability.
© 2022 HOSTRYZEN. All rights reserved.