UKB
UKB

Reputation: 1212

How do I configure a virtual host to look in 2 directories and 1 file for the request?

I want to make it so that going to domain.com/xyz will check in web/, if it doesn't exist in web/ then it will check in website/ and if it doesn't exist in either of them it will check in web/app.php

How do I configure the virtual host (with mod_rewrite) to do this?

Thanks

Upvotes: 1

Views: 109

Answers (1)

Jon Lin
Jon Lin

Reputation: 143946

Try adding this in your vhost config:

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]

The route through app.php just calls /web/app.php, it doesn't send anything to the script.

Upvotes: 2

Related Questions