Rewriting HTTP requests

It's sometime necessary to rewrite an HTTP request for one file into another file. For example, part of the content on a website may have been moved, but clients may have cached or bookmarked the old links. Alternatively, a legacy component of a website may use a different URL space to identify resources.

# rewrite all requests for content in /graphics to /images instead

$url = http.getPath();
if( string.startsWith( $url, "/graphics/" ) ) {
   $newurl = string.regexsub( $url, "^/graphics/", "/images/" );
   http.setPath( $newurl );
}

The above example uses a regular expression substitution to change "/graphics/" to "/images/" in the URL. There are many other ways to manipulate strings; for example, the string.skip() function can remove the 10-character "/graphics/" prefix from the start of the string:

   $newurl = "/images/" . string.skip( $url, 10 );
Owen Garrett [Zeus Dev Team] 01 July 2005  Permalink  
Leave a comment ...
Your email address will not be displayed.
Your URL will be displayed.
This public messageboard is not a forum for technical support. To report technical support problems, please contact our dedicated Support team using the instructions at the bottom of this page.
Options:
 
(Line breaks become <br />)
(Set cookies for name, email & url)
Download Free ZXTM Desktop Edition

Recent Articles

Other Resources



www.zeus.com