This flexible solution is editor-friendly because only one form for each page must be filled and it becomes a source for different page templates.
For latest documentation, source code and binaries visit module's home page page.
How it works
To illustrate how it works, consider differences between using default friendly Url provider and Making Waves’ rule based Url provider
For default friendly url provider
- /Articles/Website-Launch url is translated to /Templates/Articles/NewsTemplate.aspx?id=1234
- /Articles/Website-Launch/Mobile returns 404 error
For rule based url rewrite provider with configured mobile rule (as suffix rule)
- /Articles/Website-Launch is translated to /Templates/Articles/News.aspx?id=1234
- /Articles/Website-Launch/Mobile is translated to /Mobile/Templates/Articles/News.aspx?id=123&Rule=”Mobile”
- /Articles/Website-Launch/Lite is translated to /Lite/Templates/Articles/News.aspx?id=123&Rule=”Lite” (e.g. Lite/Full website version like MSDN)
Additionaly further template selection can be made based on User Agent (sent by browser), so for example IPhone users can be served a different version then other mobile devices, which may have low resolution displays.
Note: Url suffix (“Mobile”) and path for templates (“/Mobile/Templates/”) are examples and can be configured in web.config
You can check how it works in production at Making Waves’ website. Additionaly if you visit this website from mobile device you will be automatically redirected to mobile version.
- http://makingwaves.no – regular website version
- http://m.makingwaves.no - mobile version using same page data as source for a template
Rule selection
When client tries to access any Url rule based rewriter, selects rule which will perform further processing. All rules are probed for matching and first, which accepts url, is responsible for template selection.
In an example below, third rule matches url and then selects the fourth template. After page is rendered, the rule is also responsible for transforming non-friendly urls into corresponding friendly urls for this rule from page markup.
Features
- Configurable in web.config and programmatically
- Extensible rule selection engine
- Translates urls in rendered page using rule choosen to select template
Supported rules
- AgentBasedSubDomainMatchingUrlRewriteRule - Uses sub domain to match rule.
- SuffixMatchingUrlRewriteRule - Uses suffix to match rule.
- AgentBasedSuffixMatchingUrlRewriteRule - Works like suffix rule but additionaly template selection can be performed based on User Agent sent by browser.
- PrefixMatchingUrlRewriteRule - Uses prefix to match rule.
Download
Visit dowload section at Module's page
Sample Configuration
In web.config
<configSections> <section name="makingWaves.urlRewrite" type="MakingWaves.Common.EPiServer.UrlRewriting.Configuration.UrlRewriteSection, MakingWaves.Common.EPiServer.UrlRewriting"/> ... </configSections> <makingWaves.urlRewrite> <rules> <add name="MobileRule" type="MakingWaves.Common.EPiServer.UrlRewriting.AgentBasedSuffixMatchingUrlRewriteRule, MakingWaves.Common.EPiServer.UrlRewriting" rootPath="MobilePath/Regular" urlSuffix="Mobile"> <ruleProperties> <add propertyType="agent" agentPattern=".*Android.*" pathSuffix="MobilePath/Android"/> <add propertyType="agent" agentPattern=".*IPhone.*" pathSuffix="MobilePath/IPhone"/> </ruleProperties> </add> </rules> </makingWaves.urlRewrite>
In episerver.config
<episerver> <urlRewrite defaultProvider="RuleBasedUrlRewriteProvider"> <providers> <add name="RuleBasedUrlRewriteProvider" description="My provider supporting multiple templates" type="MakingWaves.Common.EPiServer.UrlRewriting.RuleBasedUrlRewriteProvider,MakingWaves.Common.EPiServer.UrlRewriting"/> ... </providers> </urlRewrite> </episerver>
Additionally, if you want a mobile client to be redirected to a proper version of a page consider using the following snippet using extension method GetLinkUrlByRule:
if (HttpContext.Current.Request.Browser.IsMobileDevice) { this.Response.Redirect(CurrentPage.GetLinkUrlByRule("MobileRule")); }
Contributed by
- Andrzej Zapotoczny (andrzej.zapotoczny _mail_at_ makingwaves.pl)
- Mirosław Jedynak (miroslaw.jedynak _mail_at_ makingwaves.pl)
- Krzysztof Danielewisz (krzysztof.danielewicz_mail_at_makingwaves.pl)
No comments:
Post a Comment