[Zope] Question about the base href that Zope adds
automatically
Richard Barrett
R.Barrett@ftel.co.uk
Thu, 08 Nov 2001 12:43:00 +0000
At 12:30 08/11/2001 +0100, Jan-Frode Myklebust wrote:
> >
> > can anyone explain me why zope always adds the <base
> > href="http://my.server.com/" /> to every HTML file it's serving. What's the
> > purpose of this, and is it really necessary?
>
>
>It's because when a browser accesses http://host/folder and
>http://host/folder/ your browser should understand the relative URL
>within your documents.
>
>Without the basehref, your browser will think that http://host/folder
>is a html-file, and prepend http://host/ to relative URLs. It will
>however understand that http://host/folder/ is a folder, and prepend
>http://host/folder/ to relative URLs there. So depending on the
>trailing slash, you might get different results.
While the explanation is correct it is arguable that Zope is wrong in
resolving the problem in this way.
If you look at Apache's behaviour, a request for http://host/folder yields
a 301 Moved Permanently response redirecting the browser to
http://host/folder/. The browser then has to make a second request for
http://host/folder/ which is satisfied. The fact that this second request
usually yields the contents of http://host/folder/index.html (or whatever
file is specified by Apache's DirectoryIndex directive) is OK as applying
relative URLs to page URLs like http://host/folder/ and
http://host/folder/index.html gives the same result.
The problem is that Zope is treating http://host/folder and
http://host/folder/ as being equivalent absolute URLs, when they are not
from a URL parsing/joining standpoint, and is circumventing the problem
this creates by inserting a <base> tag into the response.
There is an argument for saying that Zope should be modified so that if the
requested URL does not end in a '/' and the object it then address is
derived from ObjectManager, it should redirect the browser to the requested
URL + '/'.
That said, if you insert your own <base> tag in a page, Zope doesn't mess
with it, and you are going to get the results you should expect, i.e. the
browser will interpret the relative URLs on the page with respect to the
base URL you specified rather than the one that Zope would have supplied,
this latter being the URL for the directory from which the page was served.
> >
> > By the way, is there an easy way to get rid of this if it's not necessary?
> >
>
>Put in your own, or edit python/ZPublisher/HTTPResponse.py if you
>*really* want to get rid of it.
>
>
> -jf
>
>_______________________________________________
>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 )