0

我真的不知道如何用一句话来描述我的问题,所以我将用一个例子来解释:

假设我有一个如下所示的文件夹结构:

/根

/root/clientfolder1/testfile.php

/root/clientfolder2/testfile.php

ETC...

并且 testfile.php 在所有子文件夹中都是相同的。

现在假设我刚刚在所有子文件夹中推出了一个名为 testfile2.php 的新文件,所以现在 testfile2.php 存在于所有子文件夹中。

我添加了一个重定向,将旧的 testfile.php 指向新的 testfile2.php

因此,在我的 .htaccess 中,我添加了以下内容(是的,'RewriteEngine On' 已在 .htaccess 文件中设置):

RewriteRule (.*)/testfile\.php /$1/testfile2.php [R=301,L]

好的,现在一切似乎都正常,但是(这是事情变得棘手的地方)在我的 htaccess 文件中,我还为多个域设置了规则,以指向特定的文件夹,如下所示:

RewriteCond %{HTTP_HOST} domain-one.com
RewriteCond %{REQUEST_URI} !^/clientfolder1
RewriteRule ^(.*)$ clientfolder1/$1 [L]

RewriteCond %{HTTP_HOST} domain-two.com
RewriteCond %{REQUEST_URI} !^clientfolder2
RewriteRule ^(.*)$ clientfolder2/$1 [L]

ETC...

我还有一个主站点(默认域名),用于我的主站点(根目录中的文件)让我们称之为 main-domain.com

所以以下工作:

domain-one.com/testfile.php
domain-one.com/testfile2.php
domain-two.com/testfile.php
domain-two.com/testfile2.php
main-domain.com/clientfolder1/testfile.php
main-domain.com/clientfolder2/testfile.php

现在这是我的问题/问题:

我在上面添加的新重定向以用 testfile2.php 替换 testfile.php 导致发生以下情况:

domain-one.com/testfile.php重定向到: main-domain.com/clientfolder1/testfile2.php

但我需要它重定向到domain-one.com/testfile2.php

我无法让它工作......并且感到沮丧,因为我确信有一个简单的解决方案,我只是错过了一些明显的东西。这可以做到吗?怎么做?

在此先感谢您的帮助-非常感谢!!

4

1 回答 1

1

Apache 完全按照您的规则执行。

RewriteCond %{HTTP_HOST} domain-one.com

如果域是“domain-one.com”...

RewriteCond %{REQUEST_URI} !^/clientfolder1

...并且 URI 不“/clientfolder1”开头 ...

RewriteRule ^(.*)$ clientfolder1/$1 [L]

...然后在 URI 前面加上“clientfolder1/”。

于 2012-08-31T21:00:37.340 回答