[Zope3-dev] Apache rewrite rules and URLs: an experiment
PeterMayne at ap.spherion.com
Mon Oct 25 22:01:02 EDT 2004
I've set up a rewrite rule in Apache 2.0.52 to pass requests through to
Zope, as shown in chapter 4 of Stephan's book. The rewrite rule worked
correctly, but it took me a while to realise it, because of the way I'd
written my hrefs.
My application uses a skin called "imdb", so I have to make sure that
requests that reach Zope have "++skin++imdb" in the URL. As I'm
developing my application, I can manually include the skin, but I'd like
to hide this from the users, so my rewrite rule adds the skin to the URL.
Therefore, my application must use URLs that make sense whether I'm
accessing Zope directly, or via the Apache front end.
The rewrite rule is:
where Zope is running on chmeee, and Apache is running on wu.
In my configure.zcml for the skin, I define the resource "z3logo.gif" in
the "imdb" layer as follows:
<resource name="z3logo.gif" file="resources/zope3logo.gif" layer="imdb"/>
This means that I have to use the URL "/++skin++imdb/@@/z3logo.gif" to
access this resource: if I use "/@@/z3logo.gif", I (correctly) get a
I added the following code to the skin's index.html page:
<a href="/++skin++imdb/@@/z3logo.gif">absolute with skin</a>
<a href="++skin++imdb/@@/z3logo.gif">relative with skin</a>
'/@@/z3logo.gif'">absolute with path</a>
Obviously, including the hostname in the URL isn't a good idea.
First, I tried accessing the page directly, at
The application URL is "/++skin++imdb".
The resulting URLs are:
Only three of these are correct: the relative URL, the absolute with
skin URL, and the absolute with path URL. (Although the relative with
skin URL returns the resource, having the skin in the URL twice isn't
what we want.)
Next, I tried accessing the page via Apache, at http://wu/imdb/.
The application URL is "/imdb".
The resulting URLs are:
Only two of these are correct: the relative URL, and the absolute with
path URL. (Again, the relative with skin URL returns the resource, but
Zope sees the skin in the URL twice, so we'll put this down as incorrect.)
Therefore, there are only two ways of specifying URLs that work properly
when accessed directly and via Apache. If you know where your target is
relative to your current page, use a relative URL. If you can't use a
relative URL (for instance, a link in a template to the home page), you
have to use request.getApplicationURL(path_only=True) to create an
I also tried the following rewrite rule:
where the skin comes after the virtual host, rather than before. This
time, none of the URLs are correct: though the relative with skin and
absolute with skin URLs work, they have the skin in the URL twice, and
although the relative URL works, it contains a double slash. (I'm being
quite picky here. :-) Furthermore, the user ends up seeing the skin in
the URL as well, so this probably isn't a good rule to use.
Comments? Stephan, am I missing something?
Spherion Technology Solutions
Canberra, ACT, Australia
"You're given the form, but you have to write the sonnet yourself.
What you say is completely up to you." - Mrs. Whatsit
More information about the Zope3-dev