问题

问题

我正在尝试使用 Apache 2(在 Ubuntu 机器上运行)创建自动子域

我已经使用该VirtualDocumentRoot指令对文档根目录进行了初始声明,在我的虚拟主机文件中内容如下:

<VirtualHost *:80>
VirtualDocumentRoot /var/www/dev/branches/%1/public/
ServerAlias *.dev.example.com
<Directory />
    Options Indexes FollowSymLinks Includes ExecCGI
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>
</VirtualHost>

这对于第一部分来说效果很好,因此对的请求foo.dev.example.com具有文档根目录/var/www/dev/branches/foo/public,这很好。

问题

唉,*.htaccess我存储在公共文件夹中的文件似乎不起作用。

所有的请求都应该通过公共文件夹中的index.php发送,如该.htaccess文件所示:

Options -Indexes
<IfModule mod_rewrite.c>
  RewriteEngine on  
  # redirects requests to index.php where no file or directory exists
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule .* index.php
</IfModule>

一个请求可以foo.dev.example.com工作,但是一个请求会foo.dev.example.com/subdir失败。

帮助!

编辑:

我有一个错误日志显示这是一个 mod_rewrite 问题:

[Thu Aug 04 14:05:45 2011] [error] [client 217.206.134.99] 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.
[Thu Aug 04 14:05:45 2011] [debug] core.c(3063): [client 217.206.134.99] r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /var/www/dev/branches/amy/public/index.php
[Thu Aug 04 14:05:45 2011] [debug] core.c(3069): [client 217.206.134.99] redirected from r->uri = /user/login
[Thu Aug 04 14:05:45 2011] [debug] mod_deflate.c(615): [client 217.206.134.99] Zlib: Compressed 630 to 389 : URL /var/www/dev/branches/amy/public/index.php

答案1

你可以使用以下规则或多或少地实现这个功能:

Options -Indexes
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php [L]
</IfModule>

唯一的问题是,如果其中一个目录中有默认索引页,则只能直接访问,http://domain.tld/subdir/index.php 只需使用http://domain.tld/subdir/将其重写为http://domain.tld/index.php

相关内容