【问题标题】:.htaccess redirect secondary domain to primary domain with SSL.htaccess 使用 SSL 将辅助域重定向到主域
【发布时间】:2014-11-07 07:08:32
【问题描述】:

我想将我的辅助域重定向到我的 .com 主域,这样当我访问 domain.asia 或 www.domain.asia 时,它会将 URL 重定向到 https://www.domain.com。我遇到的问题是重定向到https://www.domain.asia(不是 .com)并且 .asia 域没有安全证书,因此会显示警告。

如何访问 domain.asia 并将其重定向到 https://www.domain.com

辅助域与主域停放在同一台服务器上。这是我的 .htaccess 文件:

# redirect to .com
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [NC]
RewriteCond %{HTTP_HOST} ^(www\.)?domain\.asia$ [NC]
RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]

# redirect to www
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]

# redirect to https if not
RewriteCond %{HTTPS} !=on
rewritecond %{HTTP_HOST} ^(www\.)?domain\.com$ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

【问题讨论】:

    标签: .htaccess redirect ssl


    【解决方案1】:

    你必须使用:

    # redirect to .com
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.co\.uk$ [OR,NC]
    RewriteCond %{HTTP_HOST} ^(www\.)?domain\.asia$ [NC]
    RewriteRule ^(.*)$ https://www.domain.com/$1 [R=301,L]
    

    with OR,使用它来将规则条件与本地 OR 而不是隐式 AND。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-01-25
      • 1970-01-01
      • 2013-06-16
      • 1970-01-01
      • 2014-08-19
      • 2013-02-20
      • 2023-03-09
      • 1970-01-01
      相关资源
      最近更新 更多