我想将整个目录及其子目录从一个 Apache 服务器 A 移动到另一个 Apache 服务器 B,然后创建从 A 到 B 的重定向。
即
http://server_a.com/docroot/dir
http://server_b.com/docroot/dir
.
这是我所做的:
- 我将
dir
下的文件和目录结构从 A 复制到 B - 我删除了 A 上的目录
dir
- 我在服务器 A 上的
docroot/.htaccess
中创建了一个规则,该规则读取
Redirect permanent dir/ http://server_b.com/docroot/dir/
但是当我去http://server_a.com/docroot/dir/path/to/file/index.html
时,即使目标页面http://server_b.com/docroot/dir/path/to/file/index.html
已启动,我也会得到403禁止访问。
我知道 Apache 会读取.htaccess
,因为它可以正确控制server_a
的其他部分。我不在这些服务器上扎根。我也尝试过RewriteRule
,结果完全相同。
在这种情况下,我应该如何创建重定向?谢谢。
如果您启用了mod_rewrite,则可以执行此操作
RewriteEngine On
RewriteRule ^/?docroot/dir(/.*)?$ http://server_b.com/docroot/dir$1 [R=301,L]
将其放在文档根目录http://server_a.com/
的 .htaccess 文件中。
注意:
首先删除浏览器缓存。
旧URL中的前导/
。喜欢这个:
Redirect permanent "/dir" "http://server_b.com/docroot/dir/"
有关更多详细信息,请参阅 mod_alias 文档。