简体   繁体   English

如何从HTTP重定向到HTTPS

[英]How to redirect from HTTP to HTTPS

The desired URL is https://www.mysite.com 所需的URL是https://www.mysite.com

I'd like to redirect all the followng URLs to be like the above URL. 我想将所有后续URL重定向为与上述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 如果后面有任何内容,例如http://www.mysite.com/photo/1 ,则使用相同的路径重定向URL: https://www.mysite.com/photo/1 : https://www.mysite.com/photo/1

Why ! 为什么 Cause i've installed SSL Certificate 原因我已经安装了SSL证书

I've used .htaccess with that code 我已经在代码中使用了.htaccess

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 但它总是将所有重定向到https://mysite.com而我恰好需要https://www.mysite.com

so any help ~ thanks 所以有帮助〜谢谢

Try this 尝试这个

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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