首页 文章

将非www(http)和www(http)重定向到https:// www

提问于
浏览
2

我试图从非www(http)和www(http)重定向到https://www但它不起作用 . 需要以下工作 . 请帮忙

当前的htaccess文件

rewritecond %{http_host} ^example.com [nc]

rewriterule ^(.*)$ https://www.example.com/$1 [r=301,nc]

试过以下规则

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

1 回答

  • 0

    你可以用这个:

    RewriteEngine on
    
    RewriteCond %{HTTP_HOST} ^example\.com$ [NC,OR]
    RewriteCond %{HTTPS} off
    RewriteCond %{HTTP_HOST} ^(?:www\.)?(example\.com)$ [NC]
    RewriteRule ^.*$ https://www.example.com%{REQUEST_URI} [NE,L,R=301]
    

相关问题