将一个 TLD 的所有页面 + 单个目录重定向到另一个 TLD 的根目录

Redirect all pages of one TLD + a single directory to the root of another TLD

Redirect all pages of one TLD to another 中有一个清晰的示例,说明如何从一个 TLD 的根目录重定向到另一个 TLD 的根目录。但是我想在我的 .htaccess 文件中添加一个重写条件和规则,它将执行以下重定向...

www.example.com/one  -->  www.example.co.uk
www.example.com/one/two  -->  www.example.co.uk/two
www.example.com/one/two/three  -->  www.example.co.uk/two/three

所以基本上它会将 URL 重定向到 TLD 已更改且路径中的第一个目录 (/one) 已删除的目录。

所以像这样的东西应该在你的虚拟主机中 www.example.com

 RewriteEngine On
 RewriteRule ^/one(.*) www.example.net/ [R=301,L]

R=301 使浏览器缓存答案并将对该目标的下一个请求直接发送到相应的 URL。所以在测试时清除你的缓存 ;)

或者,如果您不想看到被重定向的请求者:

 RewriteRule ^/one(.*) www.example.net/ [P,L]

这需要激活 mod_proxy 模块。


一个旁注:请在示例中使用 example.com,因为无法使用 domain ;)