Я пытаюсь создать автоматические поддомены с помощью 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
Вы можете заставить это более или менее работать, используя следующие правила:
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