|
|
 |
 |
 |
finalFilter.rewriteURLs
This callback rewrites urls in a page so that they begin with the url that the user entered to get to the site. Thus many entries in config.mainresponder.domains, even siteTrees, can point to the same Manila website and pages are always rendered as if the site had been installed with the user entered url.
This script is perfectly general, but it requires that there is at last one script in config.mainResponder.callbacks.pathEvaluation because that's the only time that an entry called domainPath is placed in the page table by mainresponder.respond if you don't have an entry insert a script at config.mainResponder.callbacks.pathEvaluation.rewriteURLs with the body return true.
One major gotcha is that the Manila referer check prevents posting.
The rewrite process is compatibe with the ManilaFixer turboCache because pages are cached before the rewrite process is invoked.
| «config.manila.callbacks.finalFilter.rewriteURLs : 02/04/13, 18:23:10 by David Bayly, Jobsurf Ltd. UK |
| |
«This callback rewrites urls in a page so that they begin with the url that the user |
| |
«entered to get to the site. Thus many entries in config.mainresponder.domains, even siteTrees, can |
| |
«point to the same Manila website and pages are always rendered as if the site had been installed |
| |
«with the user entered url. |
| |
«This script is perfectly general, but it requires that there is at last one script in config.mainResponder.callbacks.pathEvaluation |
| |
«because that's the only time that an entry called domainPath is placed in the page table by mainresponder.respond |
| |
«if you don't have an entry; insert a script at config.mainResponder.callbacks.pathEvaluation.rewriteURLs with the body |
| if not defined(domainPath) |
| |
«msg(string.popfilefromAddress(adrSiteRootTable)) |
| |
for adr in @config.manila.sites |
| |
if not (defined(adr^) and defined(adr^^)) |
| |
if adr^ == adrSiteRootTable |
| |
newURL = "http://" + host + "/" + nameOf(adr^) + "/" |
| |
«bundle «strip site related part of path |
| |
«local (subPath = string.popFilefromAddress(adrObject) - string.popFileFromAddress(adrSiteRootTable)) |
| |
«subPath = string.lower(string.replaceAll(subPath, ".", "/")) |
| |
«if subPath == "" «02/04/16, 06:38:34 by DAB |
| |
«local (ix = string.patternMatch(subPath, string.lower(path))) |
| |
«local (lastID = string.lower(string.nthField(subPath, "/", string.countFields(subPath, "/")))) |
| |
«if {"index", "default"} contains lastID |
| |
«subPath = string.mid(subPath, 1, string.length(subPath) - string.length(lastID)) |
| |
«if subPath == "/" «02/04/16, 06:38:30 by DAB |
| |
«ix = string.patternMatch(subPath, string.lower(path)) |
| |
«newURL = string.delete(path, ix +1, infinity) «trailing slash |
| |
«newURL = string.urldecode(path) «02/05/04, 14:53:16 by DAB |
| |
if sys.os() == "MacOS" «02/06/21, 17:58:11 by DAB |
| |
newURL = string.latinToMac(string.urldecode(path)) «02/06/21, 17:58:06 by DAB |
| |
newURL = string.urldecode(path) «02/05/04, 14:53:16 by DAB |
| |
bundle « removing that part of pta^.path that is WITHIN the site from newurl |
| |
local (subPath = string.popFilefromAddress(adrObject) - string.popFileFromAddress(adrSiteRootTable)) |
| |
subPath = string.lower(string.replaceAll(subPath, ".", "/")) |
| |
if subPath != "" «02/04/16, 06:38:34 by DAB |
| |
local (ix = string.patternMatch(subPath, string.lower(newurl))) |
| |
local (lastID = string.lower(string.nthField(subPath, "/", string.countFields(subPath, "/")))) |
| |
{"index", "default"} contains lastID |
| |
subPath = string.mid(subPath, 1, string.length(subPath) - string.length(lastID)) |
| |
if subPath != "/" «02/04/16, 06:38:30 by DAB |
| |
ix = string.patternMatch(subPath, string.lower(newurl)) |
| |
lastID == "[\"#objectnotfoundhandler\"]" «remainingpath contains site portion |
| |
ix = string.patternMatch(string.lower(remainingPath), string.lower(newurl)) |
| |
newURL = string.popTrailing(string.delete(newurl, ix, infinity), "/") + "/" |
| |
loop «walk UP the site tree table |
| |
«local (s = xml.getAttributeValue(adr, "name")) |
| |
«newURL = "/" + s + newURL |
| |
adr == adrSiteRootTable «02/04/16, 19:19:23 by DAB |
| |
parentOf(adr^) == @config.mainresponder.domains |
| |
newURL = "http://" + host + "/" + string.popLeading(newURL, "/") |
| renderedText = string.replaceAll(string.replaceAll(renderedtext, "\"" + ftpSite^.url, "\"" + newURL, false), "'" + ftpSite^.url, "'" + newURL, false) |
Relative to Frontier version 9.7b10
|