Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

I am trying to re-organize our web server and segregate download-able files from the HTML/content of the site. I have setup a "data" directory like so:

/data
  /public
    /pdf, /image, /audio, etc...
  /protected
    /pdf, /image, /audio, etc...

So everything in /public is fully accessible, everything in /protected is behind ModAuth.

My question is, is there anyway to directly link files from within the "file-type" sub-directories? This would make all URLs of the form "/public/something.jpg" or "/private/mydoc.pdf" without the need for subdirectories in the URL. However, I still want to use the subdirectories for my own organization.

This is not a very big issue, just something I got curious about as I started working on this.

share|improve this question

1 Answer 1

up vote 1 down vote accepted

This would be a job for mod_rewrite:

http://httpd.apache.org/docs/current/mod/mod_rewrite.html

Or, perhaps more on SF:

Everything You Ever Wanted to Know about Mod_Rewrite Rules but Were Afraid to Ask?

You'd have something along the lines of:

RewriteEngine On
RewriteRule /public/(.*)\.jpg        /public/image/$1.jpg
RewriteRule /public/(.*)\.pdf        /public/pdf/$1.pdf

and so on, for however many types you have.

share|improve this answer
    
thanks this is exactly what i was looking for. –  Alex Ciarlillo May 29 '12 at 16:40

Your Answer

 
discard

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.