samedi 17 juillet 2021

.htaccess redirect https and automatically add www. if no subdomain exists

Need help,

for my site hosting at Planethoster, I tried to force the HTTP to HTTPS and without www. automatically with https://www.

With this code in .htaccess

RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R,L]
RewriteCond %{HTTP_HOST} ^[^.]+\.[^.]+$
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [L,R=301] 

But the problem when I just use the url mydomain.com without www. it returns a strange url: https://www.mydomain. com/https:/mydomain. com/ (without espace before com)

So that I can not access my site with mydomain.com I have to manually put www.

Can someone help me?




Aucun commentaire:

Enregistrer un commentaire