Redirecting aliases to the domain alias

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

I am trying to redirect domain aliases to my main domain as is described in the documentation

https://docs.kentico.com/k8/configuring-kentico/managing-sites/setting-domain-names-for-sites#Settingdomainnamesforsites-Redirectingaliasestothemaindomain

But it only works if I don't add any relative path, for example, I have domain.uk.com and I have domain.com as main domain, if I type domain.uk.com I am being redirected to domain.com and that is fine but if I use domain.uk.com/example then I am not being redirected.

My setting is:

  • Domain Alias: domain.uk.com
  • Redirect URL: {%protocol%}://domain.com{%relativepath%}

What am I missing?

Thanks!

Recent Answers


Juraj Ondrus answered on December 5, 2016 12:29

Hi,
What is your exact Kentico version please? I just tried it on 8.2.50 and it is working fine.
Have you also tried clearing the browser cache? The browser is probably caching the previous redirects to act faster. Or, I would try using a different browser to test this as well.

0 votesVote for this answer Mark as a Correct answer

Nicolás P answered on December 5, 2016 15:10

Thanks for the quick answer!

The version is 8.2.48.

I was checking the code of the method CMS.URLRewritingEngine.URLRewriter.RedirectToDomain, I did a test copying the code in a beginrequest handler, there is a condition that is not letting pass because it is comparing the relative paths, I don't now pretty sure why

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))

I was wondering why are you doing this comparison? I think here is the key to resolve my issue.

Thanks!

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 6, 2016 09:27

Hi,
Thank you for the details.
The question is why it is the same code working for me. This code is checking the current URL and its domain to see if they are different or if the path is not excluded from processing.

What are your URLs and SEO settings? Are there any paths excluded?
Have you tries also clearing the browser cache?
Is it possible to see the issue online somewhere?

0 votesVote for this answer Mark as a Correct answer

Nicolás P answered on December 6, 2016 16:00

Is there a way to reach you so I can give you more detailed information?

Thanks!

0 votesVote for this answer Mark as a Correct answer

Juraj Ondrus answered on December 7, 2016 15:29

Hi,
If you have valid support maintenance, you can send us an email message or use this form.
You can add a link to this thread in your message too.

0 votesVote for this answer Mark as a Correct answer

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