首页 文章

htaccess重定向到https和www不工作

提问于
浏览
2

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

Options +FollowSymLinks
    RewriteEngine On

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

2 回答

  • 3

    您可以使用:

    Options +FollowSymLinks
    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\. [OR,NC]
    RewriteCond %{HTTPS} off 
    RewriteRule ^ https://www.domain.com%{REQUEST_URI} [NE,R=301,L]
    
  • 0
    ## 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]
    

相关问题