To redirect all website requests to the domain with the www
prefix and enforce https
at all times, follow these steps:
- Access the main directory of your website (
public_html
), then edit the.htaccess
file and add the following settings:
Force the domain to use www:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
Force the domain to use https:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
Force the domain to use both www and https:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$ [NC]
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
After finishing, save the changes.
Note: If the .htaccess
file doesn’t exist, you can create a new one inside the public_html
directory, add the settings above, and save the file.