From: Jeff R. <dv...@di...> - 2014-07-09 22:00:42
|
There's no builtin way I know of to define a default extension. I would do this with a preauth filter, something like this: === default_extension.tcl === ns_log notice "Loading default extension" proc default_extension {why} { set url [ns_conn url] # set loglvl notice set loglvl debug ns_log $loglvl "default_extension url: $url" set file [ns_url2file $url] ns_log $loglvl "default_extension file: $file" if {![file exists $file]} { if {[file exists $file.adp]} { ns_log $loglvl "adp extension for $file found" ns_internalredirect $url.adp } elseif {[file exists $file.html]} { ns_log $loglvl "html extension for $file found" ns_internalredirect $url.html } else { ns_log $loglvl "no default extension for $file found" # will just fall through } } return filter_ok } ns_register_filter preauth * * default_extension ns_log notice "Loaded default extension" === cut here === You could also implement similar logic in a url2file handler. Maybe this is something generally useful enough (something like apache MultiViews) to include as a default module, although in that case it would make sense to make it configurable from the config file. -J John Buckman wrote: > I was wondering if there was simple of of defining the default filename > extension naviserver looks for, like there is for > "ns_param directoryfile" but for any url where the filename extension > isn't specified in the url. > > For example, if you go to: > http://localhost/about > > I want "about.adp" to be the file that is loaded. > > I've done this in aolserver two ways: > > 1) with a 404 handler > 2) or with a code path in request.c (see code sample below) > > -john > > > > ==== > /* john buckman added 4/14/06 */ > /* check if should add default filename extension of .adp */ > /* only if no / on end of url which indicates a directory */ > char * dotpos; > if (ds2.string[ds2.length - 1] != '/') { > /* if not . in the entire url, or if there is a dot before the > final / (indicating a . in a > directory name, which is ok, then add the default filename > extension */ > dotpos = strrchr(ds2.string, '.'); > if ((dotpos == NULL) || (strchr(dotpos, '/') != NULL)) { > Ns_DStringAppend(&ds2, ".adp"); > /* Ns_Log(Notice, "added default extension to get '%s'", > ds2.string); */ > } > } > /* end john buckman added */ > > request->url = ns_strdup(ds2.string); > === > > > ------------------------------------------------------------------------------ > Open source business process management suite built on Java and Eclipse > Turn processes into business applications with Bonita BPM Community Edition > Quickly connect people, data, and systems into organized workflows > Winner of BOSSIE, CODIE, OW2 and Gartner awards > http://p.sf.net/sfu/Bonitasoft > > > > _______________________________________________ > naviserver-devel mailing list > nav...@li... > https://lists.sourceforge.net/lists/listinfo/naviserver-devel > |