【问题标题】:Redirect http://www.domain.com to https://www.domain.com using .htaccess使用 .htaccess 将 http://www.domain.com 重定向到 https://www.domain.com
【发布时间】:2013-10-24 10:11:27
【问题描述】:

我想将我的域从 http 重定向到 https:

http://www.domain.com --> https://www.domain.com

有可能吗?我一直在互联网上搜索,但我只找到了:

http://domain.com --> https://www.domain.com

问题是,直接到达http://www.domain.com 的人怎么样?他们不是使用非 https 网址提供服务吗?反之亦然。我只想要从 HTTP 到 HTTPS 的简单重定向。是否可以?

谢谢

【问题讨论】:

    标签: apache .htaccess mod-rewrite redirect


    【解决方案1】:

    I just want a simple redirection from the HTTP to HTTPS

    试试这个简单的规则作为 .htaccess 的第一条规则

    RewriteCond %{HTTPS} off
    RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    

    【讨论】:

    • 将您的与 Merianos Nikos 的 = Magic 相结合。我想从非 www 重定向到 www。然后,他们将从 www 重定向到 https。这是完美的。谢谢你俩! ^_^
    【解决方案2】:

    它适用于所有版本的 php,并将强制 SSL 和 www 访问所有裸域和链接:

    RewriteCond %{HTTP_HOST} !^$
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L,NE]
    
    • 我们确实需要 NE
    • 万维网。在第 4 行是可选的
    • “关闭”是必需的。

    【讨论】:

      【解决方案3】:

      使用以下代码强制使用 www 和 SSL:

      RewriteCond %{HTTP_HOST} !^$
      RewriteCond %{HTTP_HOST} !^www\. [NC]
      RewriteCond %{HTTPS}s ^on(s)|
      RewriteRule ^ http%1://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
      

      【讨论】:

        【解决方案4】:

        <IfModule mod_rewrite.c>
        
        RewriteEngine On
        RewriteCond %{HTTPS} off
        
        # Now, rewrite any request to the wrong domain to use www.
        RewriteCond %{HTTP_HOST} !^www\.
        
        RewriteCond %{HTTP_HOST} ^tatwerat\.com [NC]
        
        RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI}
        
        </IfModule>

        【讨论】:

          猜你喜欢
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 1970-01-01
          • 2016-11-12
          • 1970-01-01
          • 1970-01-01
          • 2012-09-23
          • 1970-01-01
          相关资源
          最近更新 更多