I have recently developed a flexible and useful (I believe) implementation of UrlRewriter for Force.com sites.
Simply define routes as a pattern-target pairs. Each route can be defined from pattern String and target PageReference. Pattern can consist of regular parts as well as of named parameters starting with colon. Parameters would be passed as GET parameters of target Page Reference.
Usage example:
In this case the following rewriting will occur:
/account => /SiteAccountsList
/account?directParameter=test => /SiteAccountsList?directParameter=test (direct parameters are preserved as well)
/account/0016C000003eH88 => /SiteAccountView?accountId=0016C000003eH88
/account/0016C000003eH88/edit => /SiteAccountEdit?accountId=0016C000003eH88
/account/0016C000003eH88/contacts/US => /SiteAccountContactsList?accountId=0016C000003eH88®ionId=US
Get code or install in one click from the GitHub repo. Issues and pull requests are welcome!
Simply define routes as a pattern-target pairs. Each route can be defined from pattern String and target PageReference. Pattern can consist of regular parts as well as of named parameters starting with colon. Parameters would be passed as GET parameters of target Page Reference.
Usage example:
global class SiteUrlRewriter implements Site.UrlRewriter { List<Route> routeList = new List<Route> { new Route('/account', Page.SiteAccountsList), // --> /SiteAccountsList new Route('/account/:accountId', Page.SiteAccountView), // --> /SiteAccountView?accountId=0016C000003eH88 new Route('/account/:accountId/edit', Page.SiteAccountEdit), // --> /SiteAccountEdit?accountId=0016C000003eH88 new Route('/account/:accountId/contacts/:regionId', Page.SiteAccountContactsList) // --> /SiteAccountContactsList?accountId=0016C000003eH88®ionId=US }; // ... }
In this case the following rewriting will occur:
/account => /SiteAccountsList
/account?directParameter=test => /SiteAccountsList?directParameter=test (direct parameters are preserved as well)
/account/0016C000003eH88 => /SiteAccountView?accountId=0016C000003eH88
/account/0016C000003eH88/edit => /SiteAccountEdit?accountId=0016C000003eH88
/account/0016C000003eH88/contacts/US => /SiteAccountContactsList?accountId=0016C000003eH88®ionId=US
Get code or install in one click from the GitHub repo. Issues and pull requests are welcome!