module

Playing around with Sitecore user-friendly redirect template

Sometimes, a Sitecore web page will be managed by another vendor. In order to pass PageRank, the owner may ask you to perform 301 / 302 redirect for that page. In terms of Sitecore development, there are many Sitecore modules on Sitecore Marketplace and Github for that purpose. Frankly, I have not played around with them all yet so I suppose that I should implement my own Sitecore module based on the assumptions below:

Assumptions

  • no URL Rewrite as it’s not Sitecore user-friendly
  • retaining Sitecore item and its name
  • retaining Sitecore item’s template so there is no need to create Sitecore package for the backup before the redirect
  • the redirect is able to play around with the out-of-the-box personalization feature
  • no support for multi-item

Anything Else?

Highly recommend having a look at this awesome approach Sitecore page level rules engine personalization of my fellow Sitecore MVP Marek Musielak as well.

Personally, I wanted to play around with PackageReference in order to build and deploy my Redirect Template With Status Code Sitecore module successfully based out of various Sitecore versions (you know, I’m a super lazy developer so I don’t want to create multiple Visual Studio projects for multiple Sitecore versions)

This slideshow requires JavaScript.

How to install Redirect Template With Status Code module

Download and then install the appropriate module version below to your Sitecore instance via Installation Wizard

Hopefully, you can see something like this:

This slideshow requires JavaScript.

How to use the module

  1. download this Sitecore package (the sample site) and then install it to your Sitecore instance via Installation Wizard
  2. add new host name mvcsite.local to both the hosts file and the site bindings in IIS
  3. hopefully, you can see something like this
    • This slideshow requires JavaScript.

  4. navigate to http://mvcsite.local/intro, you would see:
    • rt_4
  5. let’s redirect http://mvcsite.local/intro to https://buoctrenmay.com/ 😀
  6. right click on /sitecore/content/MvcSite/Data/Redirects to insert a new Redirect With Status Code content item
    • rt_5
  7. open and then edit /sitecore/content/MvcSite/Data/Redirects/Redirect With Status Code item
    •  click on Insert external link of Redirect Link field to insert the URL and notice that Redirect Status Code field value is 301 by default
    • rt_6
  8. open and then edit Final Layout of /sitecore/content/MvcSite/Home/Intro item
    • rt_7
  9. on Control tab, click Add button to add new control /sitecore/layout/Renderings/Feature/Redirect With Status Code/Redirect With Status Code to main placeholder
    • This slideshow requires JavaScript.

       

  10. click on Redirect With Status Code control and then click Edit button
    • in Control Properties dialog, click on Browse of Data Source field to select /sitecore/content/MvcSite/Data/Redirects/Redirect With Status Code as data source
    • rt_10
  11. navigate http://mvcsite.local/intro, you would see:
    • rt_11

 

Note: you may want to

  • use other status code rather than 301 / 302 (update Redirect Status Code field)
    • rt_16
  • redirect to other page content (click on Insert link of Redirect Link field to insert Sitecore item)
    • rt_12
  • change template of the item you want to redirect to /sitecore/templates/Project/Page Types/Redirect With Status Code (the data will be lost so don’t forget to add Redirect With Status Code control to Final Layout via Presentation \ Details afterwards)
    • rt_13

 


Not Good Enough? Please feel free to download the source code and add your own enhancements if necessary.


Got issues?

Please send your issues (with screenshots if possible) to viet.hoang.sitecore@gmail.com so that I have a chance to understand your problem and be able to suggest the solution.

Happy Sitecore Coding!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.