EPiServerFriendlyUrlRewriteProvider rewrites urls that belong to a different site
I have two EPiServer sites linking back and forth to each other. In the test environment the two sites are only available on IP addresses. No DNS is created for the two.
Site A: [127.0.0.1]:[port X]
Site B: [127.0.0.1]:[port Y]
if site A renders a link to site B on a none friendly way (templates/page.aspx?id=120), it will be rewritten by EPiServer Friendly Url Rewriter if the two sites have the same page id in there database. The result will be a link point to a page on site A instead.
To overcome this issue you could write your one rewrite provider like this:
protected override bool IsHtmlUrlValidForRewrite(UrlBuilder contextUrl, UrlBuilder url)
if (url.Port > 0 && (url.Scheme == System.Uri.UriSchemeHttp || url.Scheme == System.Uri.UriSchemeHttps))
Settings settings = Settings.MapHostToSettings(url.Host, false);
if ((settings != null) && settings.SiteUrl.Port > 0 && settings.SiteUrl.Port != url.Port)
return base.IsHtmlUrlValidForRewrite(contextUrl, url);
Note: This will never happen in a production enviornment, since you would never render links with port numbers, but since this was part of some functionalty that needed to be tested on the testenviornment, it is not so easy to tell the customer: "But I am sure it will work in production..".
Download the provider here