【发布时间】:2013-05-06 19:51:44
【问题描述】:
我在我的机器上设置了一个本地 Apache 服务器,并使用了通配符 DNS。我已将其设置为像[foldername].loc 一样工作。因此,例如,我的htdocs 文件夹下名为MyDomain 的文件夹将通过mydomain.loc 访问。此代码工作正常,我的.htaccess 中的代码在我的htdocs 中如下:
RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www\.)?([a-z0-9-]*\.)?([a-z0-9-]+)\.loc$ [NC]
RewriteCond %3::%{REQUEST_URI} !^(.*?)::/\1/?
RewriteRule (.*) /%3/$1 [PT,QSA]
现在,上面的代码还通过子域,例如“john.mydomain.loc”。现在,我在文件夹MyDomain 中有以下文件夹结构:
MyDomain
- active
- index.php
- working
- index.php
.htaccess
在MyDomain的.htaccess中有如下代码:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteRule ^(.*)$ /active/$1 [L]
如果我理解正确的话,这应该是把http://live.mydomain.loc/ 改写为http://mydomain.loc/active/。请注意,我说的是 rewrite,而不是 redirect。
但是,使用上面的代码,我在 Apache 错误日志中收到一条消息:
[client 127.0.0.1] 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.
如果我将MyDomain 的.htaccess 更改为如下所示:
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} ^live\.mydomain\.loc$ [NC]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ /active/$1 [L]
当我使用此代码时,它总是出现 403 错误,说我无权查看文件夹 /mydomain/。如果我设置Options +Indexes,我只看到/mydomain的文件夹索引。那么上面的代码在哪里失败了?
我也用RewriteCond %{REQUEST_URI} !^/active/ 尝试了上面的代码。这对结果没有影响。
我已经尝试了两天多,但我无法弄清楚。我希望 StackOverflow 的聪明才智可以帮助解决这个问题。 :)
【问题讨论】:
标签: .htaccess mod-rewrite subdomain wildcard-subdomain