Re: Example of JS web redirects?
By: poindexter FORTRAN to All on Mon Feb 25 2019 03:20 pm
The wiki mentions that you could include a JS rewrite command in the per-directory webctrl.ini file:
REWRITE
Specifies a Javascript snippet which can modify the http_request.request_string. This allows internal redirects like the RewriteRule feature in Apache .htaccess files. The key must *begin* with the string “Rewrite” which may be followed by any legal INI key characters. The order of execution is not guaranteed.
Does anyone have an example of this?
Here's an example:
JSPreExec=load(js.startup_dir+'/doku_rewrite.js');
Rewrite=doku_rewrite();
And here's the contents of doku_rewrite.js:
function doku_rewrite()
{
var n=http_request.request_string;
// Simple replacements...
n=n.replace(/^([^\?]*\/)_media\/(.*)/,"$1lib/exe/fetch.php?media=$2");
n=n.replace(/^([^\?]*\/)_detail\/(.*)/,"$1lib/exe/detail.php?media=$2");
n=n.replace(/^([^\?]*\/)_export\/([^\/]+)\/(.*)/,"$1doku.php?do=export_$2&id=$3 ");
// This handles adding doku.php to the index bit of the URI
var pi = http_request.path_info;
if (pi[0]=='/') {
pi=pi.substr(1).replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");;
n=n.replace(new RegExp('^(.*)('+pi+'(?:\\?.*)?)$'), "$1doku.php?id=$2");
}
// If the URI ends with a slash, stuff in doku.php at the end.
n=n.replace(/^([^\?]*\/)(\?.*)?$/,"$1doku.php$2");
// index.php becomes doku.php
n=n.replace(/^([^\?]*\/)index.php/,"$1doku.php");
// Handle it.
if (n != http_request.request_string) {
// Replace all but the first '?' with '&'
n=n.replace(/(^.*\?[^\?]*)\?/g,'$1&');
http_request.request_string = n;
return true;
}
return false;
}
digital man
Synchronet/BBS Terminology Definition #36:
IBM437 = Code Page 437 (so-called IBM Extended ASCII)
Norco, CA WX: 65.0F, 50.0% humidity, 5 mph E wind, 0.00 inches rain/24hrs
---
Synchronet Vertrauen Home of Synchronet [vert/cvs/bbs].synchro.net