偷偷在域名上做一个mod_rewrite

Secretly do a mod_rewrite on domain name

我正在努力解决 mod_rewrite 问题。基本上我需要对域名进行秘密重定向,从

http://domainname.com.someotherstuff.com

http://domainname.com

此规则也应影响所有子目录。

我知道分为三个步骤:

  1. 告诉系统路径是否与我们正在寻找的相匹配
  2. 定义重写规则
  3. 将新路径传递给旧路径,以便系统知道(即使它不显示)两者匹配

我已经查找了一些帖子和资源(最接近的是 this and this),但是其中 none 可以同时解决我的两个问题——重写和保密。

谁能指出我正确的方向?

此外,有人可以解释隐藏重定向和 301 之间的权衡吗?隐藏重定向对搜索引擎不友好,对吗?

非常感谢!

参考较早的 post 以澄清 rewrite vs redirect

如果您希望客户的浏览器说 http://domainname.com, but fetch the content from http://domainname.com.someotherstuff.com, then what you want is a rewrite. You will point your customer at http://domainname.com 并且应答前端 (server/LB/etc...) 将随后将 "domainname.com" 重写为 "domainname.com.someotherstuff.com" 并发送请求到将回答该请求的后端服务。在这种情况下,我更喜欢 SNAT,因此后端直接响应前端,然后 returns 将内容 none 更明智地提供给客户。

这里有几个移动部分:

  1. domainname.com 和 domainname.com.someotherstuff.com
  2. 的 DNS 条目
  3. 前端 - F5s 是我的最爱,但您可以使用任何 linux 服务器获得类似的结果;需要能够解析 domainname.com.someotherstuff.com 并具有到后端的网络连接;服务于 http://domainname.com
  4. 的请求
  5. 后端 - 网络服务器;为 http://domainname.com.someotherstuff.com
  6. 的前端服务请求