【问题标题】:htaccess force https & www. on domain & http no www on subdomainhtaccess 强制 https 和 www。在域和 http 子域上没有 www
【发布时间】:2015-07-18 22:30:14
【问题描述】:

我如何进入 htaccess 以强制 https 和 www。在域上,& http 在子域上没有 www?

以下将http://sub.domain.com 重定向到https://domain.com

# for main domains
RewriteCond %{HTTPS} !=on [OR]
RewriteCond %{HTTP_HOST} ^domain\.com$ [NC]
RewriteRule ^.*$ https://www.domain.com%{REQUEST_URI} [R,L]


# for sub domain
RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^www\. [NC]
RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L,NE]

【问题讨论】:

    标签: apache .htaccess mod-rewrite subdomain no-www


    【解决方案1】:

    你可以使用:

    # for main domains
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
    RewriteCond %{HTTPS} off [OR]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^ https://www.domain.com%{REQUEST_URI} [R=301,L,NE]
    
    # for sub domain
    RewriteCond %{HTTP_HOST} ^(www\.)?sub\.domain\.com$ [NC]
    RewriteCond %{HTTPS} on [OR]
    RewriteCond %{HTTP_HOST} ^www\. [NC]
    RewriteRule ^ http://sub.domain.com%{REQUEST_URI} [R=301,L,NE]
    

    您需要在清除浏览器缓存后进行测试。

    【讨论】:

    • 你!你从外星人的攻击中拯救了人类的生命!谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-01-20
    • 2016-06-15
    • 1970-01-01
    • 1970-01-01
    • 2016-10-22
    • 2014-06-12
    • 1970-01-01
    相关资源
    最近更新 更多