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

Apache 如何配置虚拟主机以在2个目录和1个文件中查找请求?,apache,mod-rewrite,virtualhost,Apache,Mod Rewrite,Virtualhost,我想这样做,进入domain.com/xyz将签入web/,如果它在web/中不存在,那么它将签入website/,如果它在其中任何一个中都不存在,那么它将签入web/app.php 如何配置虚拟主机(使用mod_rewrite)来执行此操作 谢谢尝试在vhost配置中添加以下内容: RewriteEngine On # check if it exists in /web RewriteCond %{DOCUMENT_ROOT}/web%{REQUEST_URI} -f [OR] Rewri

我想这样做,进入domain.com/xyz将签入web/,如果它在web/中不存在,那么它将签入website/,如果它在其中任何一个中都不存在,那么它将签入web/app.php

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


谢谢

尝试在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
,它不会向脚本发送任何内容。

它应该是web/app.php/,后跟域后面的任何内容。所以domain.com/blah/yay会登录web/app.php/blah/yay/谢谢