Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I wonder if anyone knows if there's a way to configure Apache so that the url makes Apache fetch song1.mp3 in either directory1 or directory2?

Thanks in advance!

share|improve this question

There are a couple of ways you can accomplish this.

One as has been suggested is to simply write a PHP page called clips.php and have Options +MultiViews in either the <Directory> declaration in the httpd.conf file or in the .htaccess file in the DocumentRoot directory where the clips.php is located. I use this method to handle my GPG Key policy manager using PATH_INFO to control multiple features through the same PHP file. You can then just have it parse PATH_INFO for the filename being requested then look in either directory for the file to output back to the client being sure to set the proper header() functions for content before beginning to stream the file.

The other option I've utilized in the past was to determine which directory (directory1 or directory2) was the primary and make /clips/ an Alias for that directory. Then setup a mod_rewrite rule that checks for the files existence in the other directory and have Apache hand off that copy. I've used this more in the case where I need to override and existing file in a directory, usually overriding a file with a newer copy that is in a web application.

Both suggestions depend on whether you're scripting or your configuration modification skills are stronger. Creating the PHP file might be the more versatile means to accomplish this but it is by far not the only means available to accomplish the same task.

share|improve this answer
Thanks for your reply Jeremy. I will try to implement your 2nd suggestion as well as having a look at Joe's suggestion below. – Alex F Sep 30 '09 at 13:16
Jeremy Bouse can you please give examples for the second case? cheers prb – prb Nov 22 '11 at 17:23
Welcome to Server Fault! This is an old question. If it's answers don't help you directly then you should ask a new NEW question by clicking the Ask Question button. – Iain Nov 22 '11 at 18:11

Besides creative use of mod_rewrite you might want to look into using unionfs to merge multiple directories at filesystem level. In any case, it is a good idea to use "EnableSendfile off" whenever you serve thorugh FUSE.

share|improve this answer
Unfortunately the Apache is run on a windows system so Unionfs for merging directories is out of the question in this case. Thanks anyway. – Alex F Sep 30 '09 at 13:24

There's a number of ways to handle it.

The most straight forward is to have 'clips' be a CGI or other script that looks at the PATH_INFO sent in, and then looks in the directories you want.

... and for the less straight forward ... make 'clips' point to 'directory1', then add a 404 handler for that directory that will look in directory2, adjusting the response if it finds the file.

share|improve this answer
Thanks for your answer Joe, I will try out the "404 handler" solution. – Alex F Sep 30 '09 at 13:11

Using .htaccess, mod_rewrite, and php I've done this before.

.htaccess looks like this, for example:

RewriteEngine on
RewriteRule ^clips\.*$ /path/to/script/script.php?i=$1

In your PHP script, you would get the i variable and strip path info:


Sanitize $file to prevent anyone from reading any file on the system. Then use PHP expressions to search and see which directory, if any, to serve up. You can also do any kind of tracking or processing via this php script.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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