如何将所有的HTTP请求重定向到HTTPS [英] How to redirect all HTTP requests to HTTPS
本文介绍了如何将所有的HTTP请求重定向到HTTPS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在我的网站(例如: http://www.example.com
)的所有不安全的HTTP请求重定向到HTTPS( https://www.example.com
)。我使用PHP的BTW。我能做到这一点的.htaccess?
I'm trying to redirect all insecure HTTP requests on my site (e.g. http://www.example.com
) to HTTPS (https://www.example.com
). I'm using PHP btw. Can I do this in .htaccess?
推荐答案
更新:虽然这个答案已被接受,几年前,请注意,它的方法是的now建议不要通过Apache文档。使用重定向
代替。请参见这个答案。
Update: Although this answer has been accepted a few years ago, note that its approach is now recommended against by the Apache documentation. Use a Redirect
instead. See this answer.
RewriteEngine On
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
这篇关于如何将所有的HTTP请求重定向到HTTPS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文