【发布时间】:2015-03-13 06:46:05
【问题描述】:
我在api.host.com 有一个虚拟服务器,我需要在app.host.com/api 访问相同的内容。
在 Apache 中,httpd.conf 中有以下规则:
<VirtualHost app.host.com>
DocumentRoot "C:\webserver\public\webapp"
ServerName app.host.com
<Directory "C:\webserver\public\webapp">
Options Indexes FollowSymLinks Includes ExecCGI
AllowOverride All
Require all granted
</Directory>
Alias /api/ "C:/webserver/public/api/"
<Directory "C:/webserver/public/api/">
Order allow,deny
Allow from all
Require all granted
Options Indexes FollowSymLinks
</Directory>
</VirtualHost>
在C:/webserver/public/webapp 中,.htaccess 是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
RewriteRule ^/api/(.*)$ /api/index.php?_url=/$1 [QSA,L]
RewriteRule ^api/(.*)$ api/index.php?_url=/$1 [QSA,L]
当我访问 app.host.com/api/test 时,我得到 404 未找到,但在 app.host.com/api 中一切正常。
在C:/webserver/public/api 中,.htaccess 是:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^(.*)$ index.php?_url=/$1 [QSA,L]
与api.host.com/test 配合使用也很好。
【问题讨论】:
标签: apache .htaccess virtualhost