Sitecore SXA wild card redirect from language code url to non language code url

July 20, 2022 ·

Sitecore SXA wild card redirect from language code url to non language code url

Hi Folks

This will be a quick post as i wanted to quickly share this scenario and i am sure it will be helpful for many of you as it includes SEO inputs and how we had to change few things to support it

 


Scenario

Recently we changed the implementation of our sitemap generator as it was not respecting the "language embedding" flag, which is a known issue mentioned here , so we had to overwrite it and make our own to make it work, but all good so far so now our site map did not have any URLs with language code appended to it.

But our SEO team came up with the analysis that there are users still going to 404 page because of they are hitting URL with the language code, Although we had that flag to true in Sitecore.config settings


So, Logically all pages should be accessible only without language code in the URL

Now, we knew that if we hit pages with language code they are going to 404, but our SEO team insisted that it should go to the actual pages with 301 redirect, and it should happen site wide because of either old URL book marked or search engines might have references of it and if someone is coming from there.

Solution

Well, SXA redirect module is there from the inception but till now i only did one to one mapping of OLD to NEW url, but in this case we wanted to identify the language code (we only had one language i,e "en") in the incoming url and wanted to redirect users to non language specific URLs and that is where i started playing around with wild card pattern in the SXA redirect module.

Question i had was i will be able to write the pattern for incoming URL but how can i redirect user to pages without the language code? that is where TOKEN came into picture 

SXA redirect module provides tokens like $1, $2 and so on which will be replaced by corresponding strings from the input regex

so now it was time to test things my left side regex was like below (or refer the screenshot on the top to see how mapping was done to achieve this)

^/en(/.*)$

and gave its corresponding URL on right hand side as "/$1"

that means, redirect all incoming request with language code to the corresponding page without the language code

I tested and it worked like a charm !!! and now we did not have any users landing to error page if they hit pages with language code in the URL.

I hope this will help someone looking for something like this.

SXA creative exchange export error "Export failed. There is no storage definition in the site"

July 10, 2022 ·

SXA creative exchange export error "Export failed. There is no storage definition in the site"

Hi Team,

One more amazing troubleshooting day, And this is when one fine morning one of the developer in our team raised the FLAG that she is not able to export pages using "Export" button available in ribbon in experience editor and she was getting below exception in export wizard, and surprisingly in content editor, "Creative exchange" section and their export/import button were not showing at all.

"Export failed. There is no storage definition in the site"


 

We use azure virtual machines so she had the same copy as mine, and it was working fine on my machine, so my troubleshooting started, i was not expecting anything major out of it as i thought there must be something minor going on or some access issues as she was playing around with access to Sitecore items but it turned out something else and it took couple of hours to figure out what is going on, following are the steps which were performed to troubleshoot the issue.

Troubleshooting steps performed

1) First thing i checked was if there was no security changes that was done which was preventing the creative exchange not to work, but everything was fine there, user was admin and all roles were just fine no modifications there and no Sitecore item was given security policies 

2) I overwrote BIN folder from recent back up and all configs too, just to avoid any possibilities of any recent config changes etc developer might have done in their local, but no luck, so first conclusion was that there is no config issues of any kind.

Surprisingly, If you search this error google was not giving any fruitful results to understand whats going on 

3) So, next because SXA site gets resolved using host name, target host name and language settings defined in Site grouping, i made sure there are no issues there and correct settings are selected, but everything was just fine there.

4) There was no hints on the LOG, no error or exceptions.

5) I double checked Site Manager to make sure there is no site resolving issues while export but all looks fine there.

6) I did compare ShowConfig.aspx  of my machine where everything is fine and that developer's machine's ShowConfig.aspx and everything looked same to same, all pipelines and flow was just there are evereything was fine set up wise, so second conclusion was there is no issue with SXA module set up as site and everything works just fine.

7) I even remapped the module of "Creative exchange site set up" in the site and re-installed it by right clicking site and installing module for site and selected "Creative exchange" but same behavior and no luck.

8) I observed the the error and it is not able to find the storage definitions, so i double checked that and all settings are fine under site like below

9) Now, Because our SXA solution is multi site solution and having multiple site, i tried to check export in another site and it was working just fine there, now i was 200% sure it is issue with some kind of settings on site level.

10) So i double checked all settings on site level and everything was same to same, and i compared site grouping of both the working and non working site, and with my surprise culprit was below settings

 

So when "Enable Preview" was false the in content editor it was not showing creative exchange EXPORT/IMPORT  buttons too, and in


experience editor it was showing "Export failed. There is no storage definition in the site" message

and when you turn that FLAG to ON, everything worked fine, content editor started showing those ribbon buttons too and experience editor started working too, see below screen, in content editor the moment you click "enable preview", it started showing export and import buttons and also export in experience editor started working



Solution

If "Enable Preview" is OFF, export is not working so turn it ON, and export and import will work just fine and some how the radio button in "Export window" also started showing correct options of "Zip file" and "Folder on the server" both started showing too and export worked just fine.

Some further digging
 

After finding out the solution that it works with "Enable Preview" ON, i further tried to de-assemble the "Sitecore.XA.Feature.CreativeExchange.dll" and tried to find the root cause which are following findings, i am still working on to get the the exact conclusion but findings till now are following (Sharing, So that if anyone is interested in knowing and have any inputs to that)

 There is a class called "ExportWizard.cs" in "Sitecore.XA.Feature.CreativeExchange.Wizards" namespace which is responsible to show the export wizard with all options 

 

I will show you the implementation of this method in next screenshot from where the exception message us being shown, but if you closely see this method, it takes HOME ITEM, and that home items is coming from below code

 


this "GetSiteInfo" is under my radar and it seems, it is not getting the right context of the site and hence, Sitecore thinks that its not SXA site and not showing those creative exchange button and giving export exception, but i will have concrete findings in my next blog, but main method which gives export error is below in the code 


 


Troubleshooting continues to find the root cause...