【问题标题】:htaccess redirect if domain matches with multiple exceptions如果域与多个异常匹配,则 htaccess 重定向
【发布时间】:2017-04-18 05:58:43
【问题描述】:

我有两个域指向同一个域目录。 domain1.com sub.domain2.com

我希望所有进入 sub.domain2.com 的请求都被重定向到 domain1.com,但有以下例外:

  • sub.domain2.com/exception1/(:any)
  • sub.domain2.com/exception2/(:any)
  • sub.domain2.com/exception3/(:any)

是否可以使用 .htaccess 来实现? 谢谢。

【问题讨论】:

标签: apache .htaccess redirect dns


【解决方案1】:
RewriteEngine on
RewriteCond %{HTTP_HOST} ^sub\.domain2\.com$
RewriteCond %{REQUEST_URI} !^/exception1/ [NC]
RewriteCond %{REQUEST_URI} !^/exception2/ [NC]
RewriteCond %{REQUEST_URI} !^/exception3/ [NC]
RewriteRule ^ http://domain1.com%{REQUEST_URI} [R=301]

【讨论】:

  • 它成功了!另外,如果我也想为 root 做一个例外,我要添加什么?
  • RewriteCond %{REQUEST_URI} !^/$ [NC]
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-10-21
  • 1970-01-01
  • 2012-05-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多