尝试在Apache中redirect旧的URL。 但我无法弄清楚这是什么问题:
<Directory "/home/site/www/"> RewriteEngine On Options +FollowSymLinks Redirect permanent /test http://www.google.com </Directory>
redirect根本不起作用。 我错过了什么?
我input浏览器http:// site / test ,它给了我404错误。 从Apache日志:
[Mon May 23 18:07:09 2011] [error] [client XXXXXX] File does not exist: /home/site/www/test
Apache / 2.2.16(Ubuntu)
我之前没有遇到过这个问题,但是当你把目录指令作用域之外的redirect的时候,它确实起作用的事实似乎指出,当Apache作为一个请求接收/test时,Apache不匹配该目录指令。 文档说,当请求指向指定目录或其中的某个子目录时,Directory应该匹配 – 但是Apache可能首先检查test是否是有效的子目录,而没有发现它不在该块的内部。
我没有看到为什么离开块外的redirect不做你想要的 – 不是/home/site/www的文件根目录? 如果你确实需要限制这个redirect到你的站点的某个部分,使用Location而不是Directory ,它将独立于你的服务器的物理path来处理URL,这可能是你需要的,因为你的服务器中并不存在这个test 。
如果需要更复杂的redirect(例如,如果要redirect以/test开头的所有URL,而不仅仅是指向/test的请求),请考虑使用RedirectMatch:
RedirectMatch ^/test.* http://www.google.com
Redirect将redirect/test/example http://www.google.com/example而不是简单的http://www.google.com ,这可能是也可能不是你想要的。 这个RedirectMatch会放弃/test后面的任何内容。