如何配置虚拟主机以查看2个目录和1个文件以查找请求?

时间:2012-07-26 11:21:34

标签: apache mod-rewrite virtualhost

我想这样做,以便访问domain.com/xyz将检查web /,如果它不存在于web /然后它将检入网站/并且如果它们中的任何一个都不存在它将检入web / app.php

如何配置虚拟主机(使用mod_rewrite)来执行此操作?

由于

1 个答案:

答案 0 :(得分:2)

尝试在vhost配置中添加:

RewriteEngine On

# check if it exists in /web
RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -d
# if exists, serve the file in /web
RewriteRule ^(.*)$ /web$1 [L]

# check if it exists in /website
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -f [OR]
RewriteCond %{DOCUMENT_ROOT}/website%{REQUEST_URI} -d
# if exists, serve the file in /website
RewriteRule ^(.*)$ /website$1 [L]

# otherwise, route through app.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/web
RewriteRule ^(.*)$ /web/app.php/$1 [L]

通过app.php的路线只调用/web/app.php,它不会向脚本发送任何内容。