【问题标题】:Redirect users from specific url via htaccess通过 htaccess 从特定 url 重定向用户
【发布时间】:2015-09-27 10:52:43
【问题描述】:

是否可以通过 htaccess 或脚本将来自特定 url 的用户重定向到另一个 url? (首选 htaccess)

例如

用户来自 www.domain-a.com/sample-site/ 到 www.domain-b.net/sample-site2/ 并且应该被重定向到 www.domain-c.org/sample3/ 所有其他用户不应仅重定向来自 www.domain-a.com/sample-site/ 的用户

Domain-a 和 domain-b 是 wordpress 网站。

感谢您的帮助

【问题讨论】:

  • 域-a 和域-b 由我控制

标签: php wordpress .htaccess redirect


【解决方案1】:

假设您可以控制 domain-b.net:

RewriteEngine on    
#If user clicks a link on a page sample-site of domain A
#which you may or may not control
  RewriteCond %{HTTP_REFERER} ^http://(www.)?domain-a\.com/sample-site/? [NC]
#which aims at domain B, which you control, which runs this .htaccess file
  RewriteCond %{HTTP_HOST} ^www.domain-b.net$
#requesting page sample-site2
  RewriteCond %{REQUEST_URI}  ^/?sample-site2/?
#then rewrite to domain C page sample3
  RewriteRule ^ http://www.domain-c.org/sample3/ [R,L]

【讨论】:

  • A 和 B 属于我。我会尝试并给出反馈。谢谢
  • 好的,我将它插入到我的 htaccess 中,但它不起作用。我不明白 {http_referer} 的行。有问题
  • RewriteEngine on RewriteCond %{HTTP_REFERER} ^http://(www.)?domain-a\.de/category/li-test/? [NC] RewriteCond %{HTTP_HOST} ^www.domain-b.net$ RewriteCond %{REQUEST_URI} ^/?category/re-test/? RewriteRule ^ domain-c.org/sample3 [R,L]
  • 也许你的链接中的 HTTP_HOST 不包含www.。除此之外,如果你用# 注释掉 HTTP_REFERER 行,它是否正常工作?
  • 好的,问题是 wp 超级缓存和他的重写规则 - 我解决了这个问题。重定向现在有效,但它每次都会重定向页面 (domain-b.net/category/re-test/),不仅是当有人点击 domain-a 上的链接时。当有人来自 domain-a.de/category/li-test/ 时,我只需要重定向。现在它是一个永久重定向。
猜你喜欢
  • 1970-01-01
  • 2012-06-01
  • 2014-01-16
  • 1970-01-01
  • 1970-01-01
  • 2020-05-03
  • 2021-04-02
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多