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

时间:2012-01-10 14:18:07

标签: .htaccess redirect ssl

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

  1. http 重定向到 https
  2. https://www.domain.com.uk 重定向到 https://domain.com.uk
  3. 我尝试了以下但是没有用:

      

    RewriteCond%{HTTP_HOST} ^ www。(。*)

         

    RewriteRule ^。* $ https://%1/ $ 1 [R = 301,L]

2 个答案:

答案 0 :(得分: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]

答案 1 :(得分:0)

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?domain.com.uk
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://domain.com.uk/$1 [R=301,L]

对我来说这项工作,刚刚测试。所以http://www.domain.com.uk into https://domain.com.uk .