1

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

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
Alex F
  • 41
  • 2

4 Answers4

2

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.

Dennis Williamson
  • 62,149
  • 16
  • 116
  • 151
Jeremy Bouse
  • 11,341
  • 2
  • 28
  • 40
  • 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](http://serverfault.com/questions/ask) button. – user9517 Nov 22 '11 at 18:11
1

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.

codehead
  • 986
  • 5
  • 7
  • 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
0

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.

Joe H.
  • 1,917
  • 12
  • 13
0

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.

Dave Drager
  • 8,375
  • 29
  • 45