首页 文章

使用.htaccess将www URL重定向到非www for https

提问于
浏览
1

请提供.htaccess语法来执行以下操作:

  • http 重定向到 https

  • https://www.domain.com.uk 重定向到 https://domain.com.uk

我尝试了以下但它不起作用:

RewriteCond% ^ www . ( . *)RewriteRule ^ . * $ https://%1 / $ 1 [R = 301,L]

1 回答

  • 1

    尝试将以下内容添加到域中根文件夹中的htaccess文件中 .

    RewriteEngine on
    RewriteBase /
    
    #if not domain.com.uk then redirect to domaim.com.uk
    RewriteCond %{HTTP_HOST} !^domain\.com\.uk$ [NC]
    RewriteRule .* http://domain.com.uk%{REQUEST_URI} [L,R=301]
    
    #if not https
    RewriteCond %{HTTPS} off
    #redirect to https
    RewriteRule .* https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
    

相关问题