我正在尝试创建一个动态虚拟主机条目,目的是将所有流量重定向到 .mydomain.com到/ var / www / html / 这部分有效,但我也是一个重写条件检查目录是否存在,如果不存在,那么我想将所有流量重定向到根目录/var/www/html/index.php。
这部分无法正常工作,因为在我的测试过程中,我注意到没有任何重写变量正在工作,它们是空白的,我无法弄清楚为什么这里是我的虚拟主机配置
# get the server name from the Host: header
UseCanonicalName Off
# this log format can be split per-virtual-host based on the first field
# LogFormat "%V %h %l %u %t \"%r\" %s %b" vcommon
LogFormat "%{Host}i %h %l %u %t \"%r\" %s %b" vcommon
CustomLog logs/access_log vcommon
<VirtualHost *:80>
ServerName mydomain.com
ServerAlias www.mydomain.com
VirtualDocumentRoot /var/www/html
</VirtualHost>
<VirtualHost *:80>
ServerName vhosts.mydomain.com
ServerAlias *
VirtualDocumentRoot /var/www/html/%1
RewriteEngine on
LogLevel warn rewrite:trace4
# If the request is not for a valid directory
RewriteCond /var/www/html/%1 !-d
RewriteCond %{REQUEST_FILENAME} !-d
# If the request is not for a valid file
RewriteCond %{REQUEST_FILENAME} !-f
# If the request is not for a valid link
RewriteCond %{REQUEST_FILENAME} !-l
RewriteRule .* /var/www/html/index.php
</VirtualHost>
您会注意到我在测试和查看我的日志文件时可以使用该变量的多种用途
[Wed Jul 29 16:56:56.015818 2015] [rewrite:trace2] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [fake.mydomain.com/sid#7f5c89bcf570][rid#7f5c89ed5000/initial] init rewrite engine with requested uri /
[Wed Jul 29 16:56:56.016050 2015] [rewrite:trace3] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [fake.mydomain.com/sid#7f5c89bcf570][rid#7f5c89ed5000/initial] applying pattern '.*' to uri '/'
[Wed Jul 29 16:56:56.018361 2015] [rewrite:trace4] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [fake.mydomain.com/sid#7f5c89bcf570][rid#7f5c89ed5000/initial] RewriteCond: input='/var/www/html/' pattern='!-d' => not-matched
[Wed Jul 29 16:56:56.018411 2015] [rewrite:trace1] [pid 23898] mod_rewrite.c(475): [client xx.xx.xx.xx:4863] xx.xx.xx.xx - - [fake.mydomain.com/sid#7f5c89bcf570][rid#7f5c89ed5000/initial] pass through /
即使%1传递虚拟目录就好了,它在mod重写规则中也不起作用。变量的所有其他用途都会产生相同的结果,任何帮助都会受到赞赏。