【问题标题】:Redirect all HTTP to HTTPS将所有 HTTP 重定向到 HTTPS
【发布时间】:2015-01-13 08:36:36
【问题描述】:

我的网站上有 SSL,想将我的所有 http 页面重定向到 https 我在下面找到了一些东西并为 www.yourdomain.com 工作。

如果我还需要将所有 yourdomain.com(不带 www)转移到 https,我应该在 htaccess 中添加什么?谢谢!

RewriteEngine On 
RewriteCond %{SERVER_PORT} 80 
RewriteRule ^(.*)$ https://www.yourdomain.com/$1 [R,L]
<!-- Please put the redirect without www here, thanks-->

【问题讨论】:

标签: apache .htaccess redirect https


【解决方案1】:

简单的 Google 搜索会显示数百个结果。比如这个official FAQ

RewriteEngine On
# This will enable the Rewrite capabilities

RewriteCond %{HTTPS} !=on
# This checks to make sure the connection is not already HTTPS

RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R,L]
# This rule will redirect users from their original location, to the same location but using HTTPS.
# i.e.  http://www.example.com/foo/ to https://www.example.com/foo/
# The leading slash is made optional so that this will work either in httpd.conf
# or .htaccess context

【讨论】:

  • 谢谢!我可以只重定向那些在我的整个域中包含关键字“purchasepage”的页面吗?
  • 当然可以。稍加努力,并相应地更新答案。
  • mmm .. 如何使用关键字(例如“purchasepage”)重定向所有这些页面?你能帮帮我吗?
猜你喜欢
  • 2015-12-27
  • 2019-06-18
  • 1970-01-01
  • 2014-04-27
  • 2017-05-09
  • 2014-06-30
  • 1970-01-01
  • 1970-01-01
  • 2017-04-30
相关资源
最近更新 更多