【问题标题】:Simplify redirect domain to non-www SSL简化重定向域到非 www SSL
【发布时间】:2017-06-03 00:34:34
【问题描述】:

我正在使用以下 .htaccess 代码执行以下操作:

.htaccess

RewriteCond %{HTTPS} !=on
RewriteCond %{HTTP_HOST} ^(?:www.)?(.*)$ [NC]
RewriteRule ^ https://%1%{REQUEST_URI} [R=301,L]

RewriteCond %{HTTP_HOST} ^www.(.+)$ [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]

RewriteRule ^([^.]+)/?$ index.php?get=$1 [L]

这很好用,但这段代码还能简化吗?

【问题讨论】:

    标签: .htaccess ssl redirect


    【解决方案1】:

    您可以将http->https 规则和www 删除规则组合成一个规则,并将您的.htaccess 设置为:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} ^www\. [NC,OR]
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(.+)$ [NC]
    RewriteRule ^ https://%1%{REQUEST_URI} [R=302,L,NE]
    
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule .+ index.php?get=$0 [L,QSA]
    

    【讨论】:

    • 有趣的是这增加了一行。
    猜你喜欢
    • 1970-01-01
    • 2014-11-24
    • 2016-04-02
    • 2016-12-23
    • 1970-01-01
    • 2014-03-25
    • 2017-01-09
    • 2016-12-30
    • 1970-01-01
    相关资源
    最近更新 更多