Tuesday, April 18, 2017

Redirects In Sitecore SXA

Again the wonderful Sitecore support comes to the rescue with details on using the Redirect functionality that is out of the box with Sitecore Experience Accelerator,  until the full documentation is complete I thought I would share this with the community. 


>> If a user goes to our site with a url  like http://sitename/en/our-exports/exporting.aspx  
>> We wish them to be redirected to a sitecore item for example http://sitename/exports 
>> How is this done using the SXA redirect item please? 

You can use the Redirect Map functionality. You need to create a redirect item under /sitecore/content/[Tenant]/[Site]/Settings/Redirects and specify the mapping between URLs:

redirect.png

Important note: the exporting item must not exist. Redirection will be performed only if Sitecore XP can't find a matching item, just before the user is redirected to a 404 page. 


If you want to redirect from existing item, you can use the method described in the article you mentioned. For example, you can insert a redirect item named OldContact, which will redirect to the /Contact page:


redirect_item.png



>> Also does it support wildcards and regex? If so how is this done? 

Redirect Maps support regular expressions. General rule for a regular expression in the redirect mapping: it must start with ^ and end with $. Here is a couple of examples:

This will redirect any request to a page under /products to /anotherpage:
1.png

This example uses tokens:
2.png

Tokens are regex expressions inside parentheses. There are two tokens in the input string above:

  • (.*) - matches any character
  • ([1-9]+) - matches any numeric sequence
These tokens are used in the output string as $1 and $2. Therefore, the request to /products/something/123 will be redirected to /anotherpage/something/123.










No comments:

Post a Comment