【问题标题】:htaccess redirect to https AND www not workinghtaccess 重定向到 https 和 www 不起作用
【发布时间】:2017-06-21 09:16:09
【问题描述】:

我想将任何不安全的请求重定向到 https,并确保 url 始终使用“www”。这就是我所拥有的,但似乎不起作用。我错过了什么?

选项 +FollowSymLinks 重写引擎开启 RewriteCond %{HTTP_HOST} ^domain.com [NC] RewriteCond %{HTTP_HOST} ^www.domain.com [NC] 重写规则 ^(.*)$ https://www.domain.com/$1 [L,R=301]

【问题讨论】:

    标签: .htaccess https


    【解决方案1】:
    ## Redirecting HTTP to HTTPS
    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
    
    ## Redirecting non WWW to WWW
    RewriteEngine On
    RewriteCond %{HTTP_HOST} ^domain\.tld$ [NC]
    RewriteRule ^(.*)$ http://www.domain.tld/$1 [R=301,L]
    

    【讨论】:

      【解决方案2】:

      你可以使用:

      Options +FollowSymLinks
      RewriteEngine On
      
      RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
      RewriteCond %{HTTPS} off 
      RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NE,R=301,L]
      

      【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-24
      • 2018-10-24
      • 2022-01-11
      • 2019-12-25
      • 1970-01-01
      • 2016-01-20
      • 1970-01-01
      • 2021-11-10
      相关资源
      最近更新 更多