Apache Static Content Search

Jonathan Ellis pluglist at plug.org
Fri May 9 12:38:32 MDT 2003


Stuart Jansen wrote:
 > Is there any way to configure apache to search for static contents.
 > Something like:
 >
 > Request:  /sjansen/images/example.png
 > Check1:   /opt/webroot/sjansen/images/example.png not found
 > Check2:   /opt/webroot/global/images/example.png found
 > Returned: /opt/webroot/global/images/example.png

I doubt it would supported out of the box, but you could easily write a 
request handler to strip off the filename and do find -name...

googling, this appears to be more difficult in apache than an AOLServer. 
  If you're curious, the aolserver/tcl version would look like this:

ns_register_filter postauth /* search_for_content

proc search_for_content {conn args why} {
     set url [ns_conn url $conn]
     if [file exists [ns_url2file $url]] {
	return filter_ok ;# let the regular request processor handle it
     }

     # file didn't exist, search for static content
     regexp {.*/(.*?) $url match fname
     if [string match {*.png} $fname] {
	set find_results [exec find -name $fname /my_file_root]
	# return the first result for lack of a better heuristic
	set l [split $file_results "\n"]
	if [llength $l] {
	    set new_fname [lindex $l 0]
	    ns_returnfile 200 [ns_guesstype $new_fname] $new_fname
	    return filter_break ;# all done, stop processing
	}
     }

     # couldn't find anything
     return filter_ok
}

-Jonathan




More information about the PLUG mailing list