.htaccess simple request to redirect to https:// and www.

I would like to ask what .htaccess redirect to URL https://www. do you recommend. I am looking for a simple solution, with one redirect request.
0
give a positive ratinggive a negative rating
30 May 2019 at 05:27 PM
Hi,

In case of more websites, I have the best experience with this solution:

RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{HTTP:X-Forwarded-Proto} !https
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]


The first condition checks, if www. is included in URL. When www. is not present, it will redirect to https://www.

The second rule should be applied, if www. is included, but URL does not start with https://.

0
give a positive ratinggive a negative rating
31 May 2019 at 09:48 AM
Tim
Share on FacebookShare on TwitterShare on LinkedInSend email
x
x
2024 AnswerTabsTermsContact us