Forum OpenACS Q&A: Re: Best way to do HTTP 3xx Redirections?

Collapse
Posted by Joel Aufrecht on

One limitation of the hack I posted earlier is that it only works for failed requests that have no extensions. So, here's a hack to the request processor. Whenever a file can't be found, it tries the same url with a .vuh extension. I believe this is orthogonal to bug #23. I'm not sure if I should test and then submit this as a patch - I don't see a down side, but it solves a very narrow problem, is only a partial solution by itself (you still have to go make .vuh files), and isn't the tidiest solution (which would be a core table of redirects and associated UI).

rp_serve_abstract_file in packages/acs-tcl/tcl/request-processor-procs.tcl

if { [file isfile $path] } {
    # It's actually a file.
    ad_conn -set file $path
  } else {
    # The path provided doesn't correspond directly to a file - we
    # need to glob.   (It could correspond directly to a directory.)
        # 2003-01-21 Joel Aufrecht hack:
	# In order to support certain redirects:
	# if it's a request for a file and we don't have a file with
	# that extension but we do have a .vuh, serve the .vuh
	
	set url [ad_conn url]
	set urlvuh [string range $url 0 [string last . $url]]
	append urlvuh vuh
	
	set pathvuh [string range $path 0 [string last . $path]]
	append pathvuh vuh
	
	if { [file isfile $pathvuh] } {
	    ad_raise redirect $urlvuh
	}

	# end of Joel's hack

    if { ![file isdirectory [file dirname $path]] } {
      ad_raise notfound
    }
...