Apache重写到测试目录

Apache rewrite to test directory

如果我使用像 test.mywebsite.com 这样的子域 test,我正在尝试使用 apache 重定向在我的生产文件夹和测试文件夹之间更改目录,但我认为它陷入了无限循环。我确信这很简单,但我似乎无法弄清楚。

<Directory />       
    RewriteEngine on
    RewriteBase   /var/www/mywebsite
    RewriteCond   %{HTTP_HOST}  ^test\.[^.]+\.com$
    RewriteRule   ^(.+) %{HTTP_HOST} [C]
    RewriteRule   (.*) /var/www/mywebsite_dev   
</Directory>

编辑 我在 apache 日志中收到这样的错误。

Request exceeded the limit of 10 internal redirects due to probable configuration error. Use 'LimitInternalRecursion' to increase the limit if necessary. Use 'LogLevel debug' to get a backtrace.
redirected from r->uri = /mywebsite_dev/mywebsite_dev/
redirected from r->uri = /mywebsite_dev/
redirected from r->uri = /

如果您明确检查 test 子域,则不要使用 RewriteBase.

RewriteEngine on

RewriteCond %{HTTP_HOST}  ^test\. [NC]
RewriteCond  !^/?mywebsite_dev/ [NC]
RewriteRule ^(.*)$ /mywebsite_dev/ [L]

此外,RewriteRule 指定的路径附加在 wwwpublic_html 目录之后。所以,不要在那里提供绝对的系统文件路径,因为那样的话最终路径是不正确的。