.htaccess - 重定向http=>https(非www)+ www https=>非www https(www 无证书)

标签 .htaccess mod-rewrite

我看过很多关于重写的文章。都好。但没有一个涵盖这种具体情况。所以这是我的问题:希望你能帮忙。因为我无法让它发挥作用。

  • 我们在domain.com(非www)上运行网站
  • 我们已设置 ssl(因此仅限 https)
  • 我们有 1 个非 www 版本(非 www 版本)的证书

当我们执行所有四个测试用例时,3 个正常,1 个不正常

  1. http://domain.com =>https://domain.com =>
  2. http://www.domain.com =>https://domain.com => 好的
  3. https://domain.com => 好的
  4. https://www.domain.com => 错误。证书警告不安全

问题:现在为什么数字是 4 https://www给我这个错误。我希望第一条规则能够接收并将我们发送到非 www 版本。我该如何解决这个问题?

感谢任何帮助;P肖恩

<小时/>

这是我当前的 htaccess

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Redirect www to non-www first 
  # Added based on article http://stackoverflow.com/questions/234723/generic-htaccess-redirect-www-to-non-www
  RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
  RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]

  # Then redirect http to https (if necessary)
  RewriteCond %{HTTPS} !=on
  RewriteRule ^/?(.*) https://%{SERVER_NAME}/$1 [R=301,L]
</IfModule>

最佳答案

您可以在 .htaccess 中使用它:

<IfModule mod_rewrite.c>
  RewriteEngine on
  # Redirect www to non-www first 
  RewriteCond %{HTTP_HOST} ^www\.(.+) [NC]
  RewriteRule ^(.*) https://%1/$1 [R=301,NE,L]

  # Then redirect http to https (if necessary)
  RewriteCond %{HTTPS} off
  RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [NE,L,R=301]
</IfModule>

但是对于证书错误您无能为力。
阅读:Redirecting https://www to https://non-www - without seeing certificate error, possible?

关于.htaccess - 重定向http=>https(非www)+ www https=>非www https(www 无证书),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28362743/

相关文章:

.htaccess - htaccess 将下划线重写为特定目录的破折号

php - 我如何使用 mod-rewrite (iirf) 只重定向 php 文件

apache - Tomcat、Mod_rewrite、Mod_proxy : how do I keep the original URI path in a proxied request?

apache - .htaccess 虚拟主机的基本身份验证?

apache - Apache 的 RewriteRule 的 $1 替换不会返回第一个匹配的表达式

linux - 如何将 SSL 应用于每个页面?

php - 无法从基于 url CI 的站点中删除 index.php

apache - 重写任意数量的路径段来查询参数

.htaccess - 如何禁用 URL 中的 "?i=1"参数

php - Magento错误: SQLSTATE[42S02]: Base table or view not found: 1146 Table 'shoukatt_mgnt1.captcha_log' doesn't exist