I am wishing there's a method to do that with mod_rewrite and Apache, but maybe there's a different way to consider too.

On my small site, I've sites setup for re-skinned versions from the site for clients. When the web root is /home/blah/www, a customer directory could be /home/blah/www/clients/abc. Whenever you access the customer directory using a internet browser, I would like it to use any asked for files within the client directory when they exist. Otherwise, I would like it to make use of the file within the web root. For instance, let us the client doesn't need their very own index.html. Therefore, some code would determine that there's no index.html in /home/blah/www/clients/abc and can rather make use of the one out of /home/blah/www. Bear in mind that I'd rather not redirect the customer to the net root anytime, Among the finest to make use of the net root's file with this title when the client directory hasn't specified its very own copy. The internet browser should still indicate /clients/abc if the file is available there or perhaps in the main. Likewise, if there's a request news.html within the client directory also it DOES exist there, then just serve that file rather than the net root's news.html. Anyone's experience ought to be seamless.

I want this to dedicate yourself demands on any filename. If I have to, for instance, give a new line to .htaccess for each file I may want to redirect, it rather defeats the reason as there's an excessive amount of maintenance needed, and a high probability for errors because of the many files.

Inside your good examples, please indicate whether your code gets into the .htaccess file within the client directory, or even the web root. Web root is preferred.

Thank you for any suggestions! :)

# If requested resource exists as a file or directory, skip next two rules
RewriteCond %{DOCUMENT_ROOT}/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/$1 -d
RewriteRule (.*) - [S=2]
#
# Requested resource does not exist, do rewrite if it exists in /archive
RewriteCond %{DOCUMENT_ROOT}/archive/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/archive/$1 -d
RewriteRule (.*) /archive/$1 [L]
#
# Else rewrite requests for non-existent resources to /index.php
RewriteRule (.*) /index.php?q=$1 [L]

From Rewrite if files do not exist

RewriteCond %{REQUEST_FILENAME} !-f

Do this:

RewriteEngine on
RewriteRule ^clients/abc/ - [L]
RewriteCond %{DOCUMENT_ROOT}clients/abc/$0 -f
RewriteRule .* clients/abc/$0 [L]

I believe you would like something along wrinkles:

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}clients/$1/$2 -f
RewriteRule ^clients/([^/]+)/(.*)$ %{DOCUMENT_ROOT}clients/$1/$2 [L]
RewriteRule ^clients/([^/]+)/(.*)$ %{DOCUMENT_ROOT}$2 [L]

I appeared to possess a minumum of one trouble with each one of the good examples above. % appeared to complete the incorrect factor in a few places, plus some / figures appear to become missing. Here's my solution, which matches within the .htaccess within the web root. Rather than using two rules (one for that situation in which the file under clients/ is located, and something because of not found), all I have to check is that if the asked for file (or directory) doesn't exist. If it is available, no change is required, it may only use the file provided within the client dir. Here's the code I chosen:

RewriteEngine on
RewriteCond %{DOCUMENT_ROOT}/clients/$1/$2 !-f
RewriteCond %{DOCUMENT_ROOT}/clients/$1/$2 !-d
RewriteRule ^clients/([^/]+)/(.*)$ $2 [L]

Interesting help!