When setting up your website, you may want to redirect your domain from using the "www" prefix to the non-www version (or vice versa). This can help with branding consistency and improve SEO. In this guide, we will show you how to achieve this using the .htaccess file.

1. Access your website's files: Connect to your web server using an FTP client or access the file manager provided by your hosting provider.

2. Locate the .htaccess file: The .htaccess file is usually located in the root directory of your website. If you can't find it, create a new file and name it ".htaccess".

3. Open the .htaccess file: Use a text editor to open the .htaccess file.

4. Redirect from WWW to non-WWW: To redirect from the "www" version to the non-www version, add the following lines of code to your .htaccess file:

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

   Replace "example.com" with your actual domain name.

5. Redirect from non-WWW to WWW: To redirect from the non-www version to the "www" version, use the following code instead:


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

   Again, replace "example.com" with your actual domain name.

6. Save and upload the .htaccess file: Save the changes made to the .htaccess file and upload it back to your web server.

7. Test the redirection: Open your website in a browser and verify that the redirection is working as expected. Make sure to clear your browser cache or use a different browser to ensure that any previous redirects are not cached.

That's it! You have successfully redirected your domain from WWW to non-WWW (or vice versa) using the .htaccess file.

Note: It may take some time for the changes to propagate and for the redirection to take effect due to DNS caching.