I wonder if anyone knows if there's a way to configure Apache so that the url http://myurl.com/clips/song1.mp3 makes Apache fetch song1.mp3 in either directory1 or directory2?
Thanks in advance!
-Alex
I wonder if anyone knows if there's a way to configure Apache so that the url http://myurl.com/clips/song1.mp3 makes Apache fetch song1.mp3 in either directory1 or directory2?
Thanks in advance!
-Alex
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.
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.
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.
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:
$file=basename($_GET['i']);
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.