How to force www. with .htaccess?

Member

by emelie , in category: SEO , 4 months ago

How to force www. with .htaccess?

Facebook Twitter LinkedIn Telegram Whatsapp Pocket

1 answer

by jacey.lubowitz , 4 months ago

@emelie 

To force the use of "www" in your website's URL using the .htaccess file, you can follow these steps:

  1. Access your website's root directory using an FTP client or file manager provided by your hosting provider.
  2. Look for the .htaccess file. If you cannot find it, create a new file and name it ".htaccess" (including the dot at the beginning).
  3. Open the .htaccess file using a text editor, such as Notepad or Sublime Text.
  4. Add the following lines of code to the file:
1
2
3
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]


  1. Save the changes and upload the .htaccess file back to your website's root directory.
  2. Clear your browser's cache to ensure the changes take effect.


Now, when you access your website without the "www" prefix, the .htaccess file will redirect you to the "www" version of your site.