We implemented a feature that, based on the request details, detects the user’s device and then redirects him to the mobile version.

After migrating EPiServer version from 7.10 to 7.19 this feature stopped working – we suddenly figured out that this must be a problem related to routing and rewriting URLs.

We did the platform update (via Nugets) and it was the only change we did to our codebase.

During regression tests, the mobile version was not correctly resolved – users were getting “too many redirects” error.
The webpage has a redirect loop
During the log analysis we found that: Could not get Friendly URL for ‘/?channel=Mobile’ – no rewrite performed.
After long investigations we figured out that the issue had been related to the built-in HierarchicalUrlRewriteProvider class. The ConvertToExternal method with signature:

in our solution stopped rewriting “/?channel=Mobile” as we expected. I decompiled both 7.10 and 7.19 versions to find that ConvertToExternal method is using ConvertToExternalInternal method which now has a different implementation.

Missing language branch in rewriter

It looks like the method was refactored. Previous version used the language settings from ContentLanguage.PreferredCulture.Name or from query string – “epslanguage”.

However in the new code there is an assignment like this:

but str1 variable is not passed to UrlResolver as it was before.

Probably we would have to change our rewriting mechanism or add some additional routing configuration, but for now I’m not sure how to do this. I also checked in version 8.3.0 and the code is the same.

Fortunately ConvertToExternalInternal method is virtual, so I was able to create HierarchicalUrlRewriteProviderWithFix that derive from HierarchicalUrlRewriteProvider and override ConvertToExternalInternal method with the code from the previous version. So it now looks like this: