Personal tools
You are here: Home Linux and free software Making Zope and Plone collaborate with Google Analytics

Making Zope and Plone collaborate with Google Analytics

— filed under: , , ,

Otherwise known as the slash-ended problem.

In Apacheland, if you access a folder, Apache automatically redirects you to a new URL ending in a slash (/).  Not so with Plone or Zope -- any resource can or cannot have a slash at the end, which is not nice for neither Web caches nor Google Analytics -- it groups content based on the slash, so the same resource linked twice, once with a slash and once without a slash, those are two separate pages.

The fix

So, how do we fix this?  We fix this with the following Varnish configuration stanza:

sub vcl_recv {
    # Redirect slash-ended requests
    if (req.url != "/" && req.url ~ "/$") {
            set req.http.New-Location = regsub(req.url,"/+$","");
            error 301 "Redirecting you to the non-slash representation...";
    }
}

sub vcl_error {
    if (req.http.New-Location) {
            set obj.http.Location = req.http.New-Location;
    }
}

That is it.  The receive routine will detect the URL has a slash at the end, will rewrite the location into a temporary HTTP header, and throw an HTTP error 301.  The error routine will detect the presence of this temporary header and use it to base the Location header for the HTTP error 301 (Moved Permanently) itself.

Document Actions
Add comment

You can add a comment by filling out the form below. Plain text formatting.

Info
You are not logged in. You may optionally enter your username and password below. If you don't enter anything, this comment will be posted as 'Anonymous User'.
(Required)
(Required)
(Required)
Enter the word