[Zope] base href's tag added by Zope
DA Loeffler
DA Loeffler <David.Loeffler@bristol.ac.uk>
Wed, 7 Aug 2002 16:20:28 +0100 (BST)
Funnily enough I posted a message asking what goes on here to zope@zope
yesterday, but have since worked out what's going on.
The problem is only for index_html files. If you point your browser at
www.foo.com/aFolder, it is actually fed www.foo.com/aFolder/index_html;
in the lingo, index_html is the default method of the object aFolder.
However Web browsers don't grok Zope object orientation, so your browser
thinks it is reading a _file_ called myFolder in the root directory of
www.foo.com. So if you have a relative link <a href="bar">, the browser
thinks this is to www.foo.com/bar, not www.foo.com/aFolder/bar, because
it doesn't know aFolder is a folder (if you see what I mean).
The way Zope gets around this is to include a handler which checks if
index_html is being returned in this way, and puts in the tag
<base href="www.foo.com/aFolder/" />
and the browser resolves all relative URLs using this base, so <a
href="bar"> is now interpreted as www.foo.com/aFolder/bar, as it should
be.
If you want finer control over what happens here, you can adjust the
base returned in two ways:
1. Put in a base tag yourself (manually) - it will then not attempt to
add a new one
2. use the setBase() method on REQUEST.RESPONSE to control what base it
will put in (which has much the same effect!)
And the third way is to fiddle the source code. The setBase routine is
automatically called if the default method is being used by the Traverse
method of the BaseRequest class, defined in
/lib/python/ZPublisher/BaseRequest.py
(line 264 in my release, 2.5.1 source). If you really don't like this
behaviour you could get rid of it by removing the lines
if request._hacked_path:
i=URL.rfind('/')
if i > 0: response.setBase(URL[:i])
from this file, but then all your indexes_html will start behaving very,
very oddly! I strongly advise you not to do this.
On the other hand, if you just want to get rid of it for one file, try
writing something like
<html><head>
<!-- <base href=""> -->
</head><body>
[...]
which will confuse the setBase method - it doesn't realise the base tag
is commented out, and refrains from adding one - but this is a totally
pointless kludge.
Finally: this curious behaviour seems to be set to vanish once and for
all in Zope 3. There was an extended discussion on the Zope3-dev list,
which you can read at
http://lists.zope.org/pipermail/zope3-dev/2002-March/001164.html
should you wish to, after which it was concluded that Zope 3 should
probably use an HTTP redirect, redirecting requests to
www.foo.com/aFolder to www.foo.com/aFolder/. This is the current
behaviour of Apache, and it is preferable for a whole host of reasons
(chiefly that having <base> tags screws up certain versions of wget, and
that JavaScript doesn't recognise <base> tags in most browsers anyway).
Sorry if I have bored you; as I said, this is a problem I have recently
met myself, so all this was fresh in my mind anyway.
David
On Wed, 7 Aug 2002, Pascal Samuzeau wrote:
> Hi,
>
> Here is my first lines of the standard_html_header :
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <HTML><HEAD><META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
>
> Here is the first lines received from the server by my browser :
>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <HTML><HEAD>
> <base href="http://www.frenchradiology.net/cerf/" />
> <META HTTP-EQUIV="Content-Type" CONTENT="text/html;">
>
> As you can see my Zope's server added the base href ?
>
> How can I do to not have this href, or modify if necessary ?
>
> Sincerily
> PS
> --------------------------------------------------
> Oreka ! Nous sommes l'internet moins cher !
> Surfez 25% moins cher avec http://www.oreka.com
>
> _______________________________________________
> Zope maillist - Zope@zope.org
> http://lists.zope.org/mailman/listinfo/zope
> ** No cross posts or HTML encoding! **
> (Related lists -
> http://lists.zope.org/mailman/listinfo/zope-announce
> http://lists.zope.org/mailman/listinfo/zope-dev )
>
>