.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.
posted on 30.05.2019 at 17:27
0pnshow more
zeddzedd
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://.

posted on 31.05.2019 at 09:48
0pnshow more
TimTim
share on facebookshare on twitter
2020 AnswerTabsTermsContact us
This site uses cookies to improve your experience, for analytics and ads. By continuing to browse this site you agree to our use of cookies.