简体   繁体   中英

HTTP redirect to HTTPS

how can i redirect my site to https? i already set on cpanel domain -> redirection 从Cpanel设置中重定向详细信息

and here's my .htaccess code:

<IfModule mod_rewrite.c>
 RewriteEngine On

 RewriteCond %{HTTPS} off
 RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
 RewriteBase /
 RewriteRule ^index\.php$ - [L]

 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteCond %{REQUEST_FILENAME} !-d
 RewriteRule . /index.php [L]
</IfModule>

but when i type mydomain.com, its not redirect to www.mydomain.com and because of it, i got bad certificates. can someone know why i got this one for my website?

In these lines :

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

You have enforced all http requests into https as they are , whether come with or without www ,

So , change these lines with this :

RewriteCond %{HTTPS} off  [OR]
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^  https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

Note: clear browser cache then test

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM