Logo

Virtual hosting in CPS

Last modified: 12/13/2006 06:55 AM
Information about paths/urls handling to make it work with virtual hosting

A new URL tool (portal_url), extending the CMF one, has been designed to handle virtual hosting in CPS.

The most complex case is when part of the portal is hidden in the URL, and part of the URL is completely virtual, for instance:

  • virtual url: http://www.site.com/foo/bar/my-folder/my-file
  • zope absolute path: /cps/workspaces/my-folder/my-file

Here are the methods to remember and use:

  • utool.getRpath(object) gives 'workspaces/my-folder/my-file' (alias for getRelativeContentURL from CMF)
  • utool.getBaseUrl() gives '/foo/bar/' (would give '/cps/' without virtual hosting). This should only be used when generating URLs that are not placeful, like links to fixed images or fixed skins like the directory ones.
  • utool.getUrlFromRpath(rpath) gives 'http://www.site.com/foo/bar/my-folder/my-file' when given rpath 'workspaces/my-folder/my-file'.
  • utool.getRpathFromPath(path) gives 'workspaces/my-folder/my-file' when given '/cps/workspaces/my-folder/my-file'.

Additional methods handle breadcrumbs.

Some object methods can be used too:

  • obj.absolute_url() gives 'http://www.site.com/foo/bar/my-folder/my-file'
  • obj.absolute_url_path() gives '/foo/bar/my-folder/my-file'

You should not use the deprecated skin scripts getBaseUrl.py, getContextUrl.py or getBreadcrumbs.py anymore, but query the tool instead. Also, you should never create URLs by joining the base url and the object rpath, as it will generate incorrect URLs in the case of virtual hosting given above.

This site is powered by CPS, which includes CPSSkins. CPS and its design are Copyright © 2002-2006 Nuxeo SAS.
CPSSkins is Copyright © 2003-2006 Jean-Marc Orliaguet.
powered_by_nuxeo.png