[opencms-dev] Howto have a tree structure but server flat urls

Roman-Uhlig roman.uhlig at maxity.de
Tue May 10 13:12:43 CEST 2011


We use the OpenCms ResourceInitHandler for that. But as it has been already
said: be careful. There are cases where it makes sense, but that not
necessarily always the case. ;)
We mainly use it to create pretty short virtual URL's so the search engines
and page visitors love us. You obviously can't always provide that within
the OpenCms VFS.

There are already posts in the mailing list about the ResourceInitHandler,
it's basically something like that:


public class MyResourceInitHandler implements I_CmsResourceInit {
	
	private String m_siteRoot = "/sites/mysite";
	
	public CmsResource initResource(CmsResource resource,CmsObject
cms,HttpServletRequest request,HttpServletResponse response) throws
CmsResourceInitException 
	{
		if (request != null) {
			String siteRoot = cms.getRequestContext().getSiteRoot();
			
			if (m_siteRoot.equalsIgnoreCase(siteRoot)) {
				if (uri.matches("(?i)\\/(de|en|cs)\\/cities\\/.*")) {
					resource = cms.readResource([actual resource in the VFS]);
					cms.getRequestContext().setUri(cms.getSitePath(resource));
				}
			}
		}
		return resource;
	}
}

Best regards,
Roman
-- 
View this message in context: http://old.nabble.com/Howto-have-a-tree-structure-but-server-flat-urls-tp31439666p31584603.html
Sent from the OpenCMS - Dev mailing list archive at Nabble.com.




More information about the opencms-dev mailing list