Redirect to domain

Nicolás P asked on December 3, 2016 00:34

I just wondering what is the purpose of compare relative paths on this function

string url1 = URLHelper.RemoveProtocolAndDomain(currentResolver.ResolveMacros(text, (MacroSettings) null).TrimEnd('/'));
      string str2 = URLHelper.RemoveProtocolAndDomain(StringExtensions.ToLowerCSafe(CMS.Helpers.RequestContext.CurrentURL).TrimEnd('/'));
      string domain = URLHelper.GetDomain(url1);
      if ((str2 != url1 || domain != string.Empty && CMSString.Compare(domain, str1, true) != 0) && !URLHelper.IsExcludedSystem(CMS.Helpers.RequestContext.CurrentRelativePath))

private static bool RedirectToDomain(SiteNameOnDemand siteName, UrlRewritingAction action)
{
  SiteInfo currentSite = SiteContext.CurrentSite;
  if (currentSite == null)
    return true;
  if (currentSite.SiteIsOffline && !URLRewriter.RedirectToSiteOffline(action, currentSite))
    return false;
  string fullDomain = CMS.Helpers.RequestContext.FullDomain;
  string str1 = URLHelper.RemoveWWW(fullDomain);
  if (!StringExtensions.EqualsCSafe(currentSite.DomainName, fullDomain, true))
  {
    Hashtable siteDomainAliases = currentSite.SiteDomainAliases;
    SiteDomainAliasInfo siteDomainAliasInfo = (SiteDomainAliasInfo) siteDomainAliases[(object) StringExtensions.ToLowerCSafe(fullDomain)] ?? (SiteDomainAliasInfo) siteDomainAliases[(object) StringExtensions.ToLowerCSafe(str1)];
    if (siteDomainAliasInfo != null && !string.IsNullOrEmpty(siteDomainAliasInfo.SiteDomainRedirectUrl))
    {
      string text = StringExtensions.ToLowerCSafe(URLHelper.ResolveUrl(siteDomainAliasInfo.SiteDomainRedirectUrl, true, false));
      MacroResolver currentResolver = MacroContext.CurrentResolver;
      string url1 = URLHelper.RemoveProtocolAndDomain(currentResolver.ResolveMacros(text, (MacroSettings) null).TrimEnd('/'));
      string str2 = URLHelper.RemoveProtocolAndDomain(StringExtensions.ToLowerCSafe(CMS.Helpers.RequestContext.CurrentURL).TrimEnd('/'));
      string domain = URLHelper.GetDomain(url1);
      if ((str2 != url1 || domain != string.Empty && CMSString.Compare(domain, str1, true) != 0) && !URLHelper.IsExcludedSystem(CMS.Helpers.RequestContext.CurrentRelativePath))
      {
        string url2 = currentResolver.ResolveMacros(siteDomainAliasInfo.SiteDomainRedirectUrl, (MacroSettings) null);
        if (StringExtensions.StartsWithCSafe(url2, "www.", true))
          url2 = !CMS.Helpers.RequestContext.IsSSL ? "http://" + url2 : "https://" + url2;
        URLRewriter.RedirectPermanent(url2, currentSite.SiteName);
      }
    }
  }

This method is contained in the class CMS.URLRewritingEngine.URLRewriter

Thanks

Recent Answers


Anton Grekhovodov answered on December 3, 2016 07:04

Hi Nicolas,

There is an option in Settings application, which allows you to disable rewriting for specific pages Excluding URLs from the rewriting engine

1 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.