Contents

url-rewriting - rewrite urls with regular expression matching

This module provides a url rewriting for the PLT Web Server. It will match a host and a url, calling a rewrite function if matched.

Configuring

This module does (dynamic-require "rewrite-rules.scm" 'rewrite-rules) and (dynamic-require "rewrite-rules.scm" 'rewrite-rules-debug) if the file rewrite-rules.scm or the file rewrite-rules.ss is found in the current directory.

This file must implement a module rewrite-rules and provide two functions: (rewrite-rules) and (rewrite-rules-debug)

(rewrite-rules) --> (list of rule)

A rule is a list of two regular expressions or boolean #t and a rewriter function. If #t is used as a rule, the rule will allways match the given host or url. The match will be (list <host>) or (list <url>) : (list host:pregexp-string | #t url:pregexp-string | #t rewriter:(mhost:pregexp-match murl:pregexp-match host:string url:string) --> new-url:string )

(rewrite-rules-debug) --> boolean

Must return #t to turn on rewrite debugging; #f otherwise.

Provided functions

(url-rewrite url:url?|string?) --> string?

Matches a given url with all registered RULES and rewrites for the first match. Returns the rewritten URL as a string or the original url, if no rule matches.

This function can be used to test your url rewriting system.

(url-rewriting-debug boolean?) --> undefined

Turns on or off debugging for the url-rewriting. Works with the url-rewrite function. To turn on debugging in the web server context, see 'Configuring'