I have an user A on a server, this users has a working set of scripts (html+js+css+everything else).
I also have users B-[as much as I want]. I want those to use the exact same files, but if they have the file themselves, use that. Like a multi-user file_exists() on server level.

Say the user B has /templates/index.html, I want the site to use all over User A's files, apart from that template (which is User B's). Much like an alias, until a file exists.

Could anyone point my in the right direction, I'm able to work on server level, I simply don't know the terms, I don't know what I'm looking for.


USER A                  USER B                      USER C
/templates/             /templates/                 /templates/
    - index.html                                    
    - header.html           - header.html           
    - footer.html                                   - footer.html

USER B uses all of USER A's files, apart from header.html
USER C uses all of USER A's files, apart from footer.html

An easy way to explain: User's B&C are an alias of A, apart from the few existing files. Pretty urls have to remain working.

  • A suggestion for a better title wouldn't be bad either.
    – Martijn
    Jan 12, 2015 at 9:43
  • What's wrong with a scripted solution that uses something like file_exists()? Or do you envisage a lower server-level solution?
    – MrWhite
    Jan 12, 2015 at 12:48
  • Performance and maintanability.
    – Martijn
    Jan 12, 2015 at 13:11
  • Are these just static HTML or are we talking portions of a page like included PHP here? Jan 12, 2015 at 18:38
  • We use seperate php and html files, there is no php in htmlfiles.
    – Martijn
    Jan 13, 2015 at 8:09

1 Answer 1


If you're using Apache webserver you might use:

# Turn on redirection module in case not already on
RewriteEngine On
# If requested file doesn't exist
# and the requested file is /scripts/script.php
RewriteCond %{REQUEST_FILENAME} ="/scripts/script.php"
# then use the script made available to all users
RewriteRule ^.*$ /scripts-global/script.php [L]

Though it is probably worth mentioning that from Apache v2.2 the -f test (to see if a file exists) does not work with relative paths so if looking to replace %{DOCUMENT_ROOT} then you'll need to replace it with a full path such as /home/users/martijn.

  • This is proving VERY difficult, in combo with pretty url's, and .htaccess files and everything.
    – Martijn
    Jan 13, 2015 at 12:42
  • Rules for the above would best be put at the top of your .htaccess file, ahead of any pretty URL rules. Jan 13, 2015 at 14:15
  • You should 1st check for the initial script URL in the RewriteRule pattern (instead of the filename in RewriteCond). Checking for ^.*$ is inefficient since every request will be processed and it looks like a few of these rule blocks would be required.
    – MrWhite
    Jan 23, 2015 at 1:03
  • @w3d but surely the way I wrote it, the RewriteRule is only executed if the RewriteCond expressions (based on known values) are TRUE, whereas your method would have to execute alot of RewriteRule statements whether they apply or not, suggesting you think executing a RewriteRule might be more efficient than a few RewriteCond statements? I can believe this perhaps in terms of typing out source code but not performance, though perhaps the performance could be improved slightly by swapping the first two RewriteCond statements over so that the script filename check comes first. Jan 23, 2015 at 10:05
  • Well, yes and no. mod_rewrite doesn't work strictly top-down as your comments suggest. Apache first checks the RewriteRule pattern against the requested URL. Only if the pattern matches does the parser start checking the RewriteCond directives above it (otherwise the RewriteCond directives are simply ignored and the parser moves on to the next RewriteRule). If all the RewriteCond directives are satisfied then yes, the RewriteRule substitution is made.
    – MrWhite
    Jan 23, 2015 at 10:36

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.