简体   繁体   中英

How to redirect from HTTP to HTTPS

The desired URL is https://www.mysite.com

I'd like to redirect all the followng URLs to be like the above URL.

Bad URLs:

https://mysite.com
http://www.mysite.com
http://mysite.com
mysite.com

And if anything is trailing, like http://www.mysite.com/photo/1 for the url to be redirected with the same path: https://www.mysite.com/photo/1

Why ! Cause i've installed SSL Certificate

I've used .htaccess with that code

RewriteEngine On
RewriteCond %{HTTPS} !^on$
RewriteRule (.*) https://www.mysite.com/$1 [R,L]

but it always redirect all to https://mysite.com while i need it exactly https://www.mysite.com

so any help ~ thanks

Try this

Options +FollowSymLinks
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

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