【问题标题】:htaccess Redirect : main domain conflict with addon domainhtaccess 重定向:主域与插件域冲突
【发布时间】:2018-02-16 04:19:38
【问题描述】:

我有 2 个域,foo.com(主域)和 bar.com(附加域)托管在同一个 VPS 上。

文件夹:

public-html/    (default folder for foo.com)
├── foo/        (desired folder for foo.com)
├── bar/        (default folder for bar.com)

我想对这两个域强制使用 https 和 www 并执行 foo.com 到子文件夹 public_html/foo 的不可见重定向

我来了

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

RewriteCond %{HTTP_HOST} ^(www\.)?bar.com$
RewriteCond %{HTTPS} off
RewriteRule ^ https://www.bar.com%{REQUEST_URI} [NE,R=301,L]
    第一个域 foo.com 按预期工作,但 bar.com 不工作:
  • bar.com 指向 https://www.foo.com。我不知道为什么
  • www.bar.com 或 http://www.bar.com 或 https://www.bar.com 返回 内部 500 错误

如果我删除以下规则,bar.com 有效,而 foo.com 不再有效:

RewriteRule ^((?!foo/).*)$ /foo/$1 [L]

如何排除 bar.com 与此规则的冲突?

【问题讨论】:

    标签: .htaccess mod-rewrite


    【解决方案1】:

    这很好用:

    RewriteCond %{HTTP_HOST} ^(www\.)?bar.com$
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.bar.com%{REQUEST_URI} [NC,R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?foo.com$
    RewriteCond %{HTTPS} off
    RewriteRule ^ https://www.foo.fr%{REQUEST_URI} [NC,R=301,L]
    
    RewriteCond %{HTTP_HOST} ^(www\.)?foo\.com$
    RewriteRule !^foo/ /foo%{REQUEST_URI}  [L]
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-05-07
      • 1970-01-01
      • 2011-11-07
      • 1970-01-01
      • 2017-04-14
      • 1970-01-01
      • 1970-01-01
      • 2016-12-29
      相关资源
      最近更新 更多