Apache中配置多个虚拟目录

我在Windows 7下配置Apache2.4+php5.6+mysql5.6,服务程序安装在C盘,把网站配置在E:\webs,使用以下的配置(httpd.conf):
DocumentRoot "E:/webs"
<Directory "E:/webs">
Options -Indexes
Options +FollowSymlinks
AllowOverride None
Require all granted
</Directory>

然后在E:\webs下配置api目录,想要支持RewriteRule,但在Windows 7下发现在api目录下增加的.htaccess没有起作用,而在Linux下没有问题,于是我把.htaccess全部内容拷到httpd.conf中,加在上面内容的后面:
<Directory "E:/webs/api">
IndexIgnore *

Options -Indexes
Options +FollowSymlinks

<Files invited>
Require all granted
</Files>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} (bot|spider) [NC]
RewriteRule . - [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/ api/index.htm [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
</Directory>
这就可以正常使用api下的RewriteRule了。

现在测试时发现在有的环境下api刷出内容特别慢,于是我就想把api单独放到ssd盘上,使用下面的方式放到C:\webs\api可行:

Alias /api "C:/webs/api"

<Directory "C:/webs/api">
IndexIgnore *

Options -Indexes
Options +FollowSymlinks

AllowOverride None
Require all granted

<Files invited>
Require all granted
</Files>

<IfModule mod_rewrite.c>
RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} (bot|spider) [NC]
RewriteRule . - [F,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^api/ api/index.htm [L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?$1 [L,QSA]
</IfModule>
</Directory>

注意要加上红色部分的两行,内容来自<Directory "E:/webs/api">,如果api在E:\webs目录下就可以省这两行,不然要加上,否则会出现403没有访问权限错误。

Tags: ,

Leave a Reply


提醒: 评论者允许使用'@user空格'的方式将自己的评论通知另外评论者。例如, ABC是本文的评论者之一,则使用'@ABC '(不包括单引号)将会自动将您的评论发送给ABC。请务必注意user必须和评论者名相匹配(大小写一致)。