【问题标题】:Naked domain automaticly redirects but www not裸域自动重定向但 www 不
【发布时间】:2017-11-30 17:44:56
【问题描述】:

我想将我的流量重定向到HTTPS

来自myawesomesite.com 的它重定向到https://myawesomesite.com,来自http(s)://www.myawesomesite.com 的它根据调用转到HTTPHTTPS

怎么了? 我的虚拟主机文件是:

<VirtualHost *:80>
        DocumentRoot /var/www/myawesomesite/public
    ServerName myawesomesite.com
    ServerAlias www.myawesomesite.com
        <Directory "/var/www/myawesomesite/public/">
                AllowOverride All
                Options FollowSymLinks
        </Directory>
    ErrorLog /var/log/apache2/myawesomesite-error_log
    RewriteEngine On
    RewriteCond %{SERVER_NAME} ="myawesomesite.com" [OR]
    RewriteCond %{SERVER_NAME} ="www.myawesomesite.com"
    RewriteRule (.*) https://%{SERVER_NAME}%{REQUEST_URI}
</VirtualHost>

【问题讨论】:

    标签: apache .htaccess http redirect https


    【解决方案1】:

    这是通过重写函数强制 SSL 的正确方法:

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{SERVER_NAME}/$1 [R,L]
    

    当然,删除您当前的代码。享受吧!

    更新:

    你也可以这样做更好:

    <virtualhost *:80="">
    ServerName www.example.com
    Redirect / https://www.example.com/
    </virtualhost>
    

    【讨论】:

      猜你喜欢
      • 2015-01-07
      • 2014-03-29
      • 2012-05-05
      • 2013-10-31
      • 1970-01-01
      • 2011-08-31
      • 2017-08-31
      • 2023-03-29
      • 1970-01-01
      相关资源
      最近更新 更多