Apache 2.2 重定向除一个目录外的所有目录

FKE*_*net 9 rewrite configuration apache-2.2

我的httpd.conf文件中有这个:

<VirtualHost IP.AD.DR.ESS:80>
    ServerName example.com
    Redirect Permanent / https://example.net/
</VirtualHost>
Run Code Online (Sandbox Code Playgroud)

这成功地将以前的所有内容重定向http://example.com到其新的相应位置https://example.net。但是,我发现一个目录example.com/specialdir/必须保留在旧服务器上,因为它需要访问的数据不在新服务器上。(完成涉及其他几十个站点的迁移需要几个月的时间。)

有没有合理的方法来解决这个问题,httpd.conf或者我将不得不使用一堆.htaccess文件?我怀疑我可以用<Location>容器做一些事情,但我不知道要问正确的问题来查找信息。

hjp*_*r92 16

您可以修改该Redirect指令以使用 aRedirectMatch并使用排除模式/specialdir

RedirectMatch Permanent "^(/(?!specialdir/).*)" https://example.net/$1
Run Code Online (Sandbox Code Playgroud)

  • 它有效,但由于某种原因它添加了双斜杠,所以必须这样做:`https://example.net$1` (5认同)