Redirect requests only if the file is not found?

Posted by ZenBlender on Stack Overflow See other posts from Stack Overflow or by ZenBlender
Published on 2009-02-27T14:34:54Z Indexed on 2012/09/03 21:38 UTC
Read the original article Hit count: 185

Filed under:
|
|

I'm hoping there is a way to do this with mod_rewrite and Apache, but maybe there is another way to consider too.

On my site, I have directories set up for re-skinned versions of the site for clients. If the web root is /home/blah/www, a client directory would be /home/blah/www/clients/abc. When you access the client directory via a web browser, I want it to use any requested files in the client directory if they exist. Otherwise, I want it to use the file in the web root. For example, let's say the client does not need their own index.html. Therefore, some code would determine that there is no index.html in /home/blah/www/clients/abc and will instead use the one in /home/blah/www. Keep in mind that I don't want to redirect the client to the web root at any time, I just want to use the web root's file with that name if the client directory has not specified its own copy. The web browser should still point to /clients/abc whether the file exists there or in the root. Likewise, if there is a request for news.html in the client directory and it DOES exist there, then just serve that file instead of the web root's news.html. The user's experience should be seamless.

I need this to work for requests on any filename. If I need to, for example, add a new line to .htaccess for every file I might want to redirect, it rather defeats the purpose as there is too much maintenance needed, and a good chance for errors given the large number of files.

In your examples, please indicate whether your code goes in the .htaccess file in the client directory, or the web root. Web root is preferred.

Thanks for any suggestions! :)

© Stack Overflow or respective owner

Related posts about apache

Related posts about .htaccess