I have .htaccess in the root directory of web which should redirect all requests to https. Here is the code:
RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
RewriteCond %{HTTP_HOST} ^web\.php5\.sk$
RewriteRule ^$ www/ [L]
RewriteCond %{HTTP_HOST} ^web\.php5\.sk$
RewriteRule (.*) www/$1 [L]
But it creates an endless loop which redirects from http to https and vice versa. Where could be the problem? First two lines comes from server administrator as response to my request for https. They handles lot of http requests from devices which are not able to make https request... Thanks.
Hi friend What about this code
RewriteEngine On
RewriteCond %{SERVER_PORT} 80
#replace this yourdomain.com into your domain name
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
This is a simple, clean and tested code to redirect all traffic from http
to https
with www
(you can also remove www from your URL anytime, just remove www from url something like this https://yourdomain.com/$1
).
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.