Knowledgebase/Help Center Redirection using JavaScript | Community
Skip to main content

Knowledgebase/Help Center Redirection using JavaScript

  • January 8, 2019
  • 7 replies
  • 0 views

What is this?: A JavaScript tool that allows you to redirect in the knowledgebase/Help Center

Overview:

It is currently not possible to redirect from one Zendesk Help Center article to another Zendesk Help Center article or an external URL. 

This is ideally done using a DNS 30x redirect, which isn't currently supported by Zendesk.

There are several posts on the community talking about JavaScript redirection. I want to share my JavaScript redirection solution here so others can use it or build on it. 

This solution uses hashmapping, so it ideally will not have large performance implications. 

How to Use :

Go to the GitHub repository to begin. The code and the usage instructions are located there. 

1) Copy and paste the code and put it into your document_head.hbs file. It needs to be in <script> tags.

2) Make sure to replace the couple sections of code that are called out!

3) Add redirects! The format is ['old article id'] = new article id; The article id is the number found in the knowledgebase URL: helpcenter.com/hc/en-us/articles/360000857366

If redirecting outside of the Help Center, use the format ['old article id'] = "new url".

4) Archive any articles that are being redirected from. This ensures that users get to the new page, and not to a Zendesk authentication page.

Additional Resources:

I made a video! This will hopefully clarify any weird issues that people encounter.

 

7 replies

Nicole17
  • January 8, 2019

Thanks for sharing this tip and putting all of this together, Scott!


Jennifer16
  • January 9, 2019

Scott--another awesome tip from you!

Thanks so much for sharing this. I love that you always include a helpful video!

This will help a lot of users! I've added it to our Guide tips master list.


  • January 15, 2019

I am currently using a javascript snippet to do this, but it is not in the document_head.hbs file. Is there any advantage to having it in the document_head.hbs file versus the script.js file? 


  • Author
  • January 15, 2019

Hey Elvind,

Seeing that both document_head.hbs and script.js inject into every page, I don’t think one is the better way (I am sure a front end engineer would have an opinion, but my knowledge is limited!).

Now, the one problem I hit was my redirects wouldn’t work for me if I had the code in script.js. A zendesk authentication script ran before the redirect, so users would be redirected to a login page and not the right article.

You can double check that by testing your redirect in an incognito window. If they work fine there, then I don’t see why you would move them out of script.js.

Let us know what you find!


  • January 16, 2019

Hi Scott,

I am surprised that redirects didn't work for you if you had the code in script.js. Do you have some custom code in script.js that runs first?

Mine works in incognito without problems.

My script is based on Joe Federic's script here: https://support.zendesk.com/hc/en-us/articles/217958367/comments/360000165468

I have modified it to have variables for URLs and it builds URLs. It works, but I think it may be less efficient than yours since I am using loops.

Here's the example code:

// Redirecting old articles to new articles or redirects

//Define variables for support centre URL redirects, will be used below to build complete redirect URLs

var mainHelpCentreURL = 'https://support.example.com/hc/en-us/';
var helpCentreArticles = 'articles/';
var helpCentreCategory = 'categories/';
var helpCentreSection = 'sections/';

var secondaryHelpCentreURL = 'support2.example2.com/hc/en-us/';

//Use this for redirecting articles to articles
var one = {
"1" : "2",
};

//Use this for redirecting to sections
var two = {
"1" : "2",
};

//Use this for redirecting to categories
var three = {
"1" : "2",

};

//Use this for redirecting to landing page

var four = {
"203325983" : "",
}

//Loops for redirects

//Loop for redirecting to articles

for (var keyone in one){
if (window.location.href.indexOf(keyone) > -1){
window.location.replace(mainHelpCentreURL + helpCentreArticles + one[keyone]);
}
};

//Loop for redirecting to sections

for (var keytwo in two){
if (window.location.href.indexOf(keytwo) > -1){
window.location.replace(mainHelpCentreURL + helpCentreSection + two[keytwo]);
}
};

//Loop for redirecting to categories

for (var keythree in three){
if (window.location.href.indexOf(keythree) > -1){
window.location.replace(mainHelpCentreURL + helpCentreCategory + three[keythree]);
}
};

//Loop for redirecting to landing page

for (var keyfour in four){
if (window.location.href.indexOf(keyfour) > -1){
window.location.replace(mainHelpCentreURL + four[keyfour]);
}
};

// End of code for redirecting

  • March 13, 2020

This is incredibly useful. Thank you for sharing. Can we use this to create vanity URLs for the help center?

Ex: The actual URL of a help article in our Zendesk Guide is https://help.cricut.com/hc/en-us/articles/360043799753-Cricut-Joy-Video-Tutorials.

Can we create a redirect help.cricut.com/cricut-joy and point it to this article?


  • February 19, 2021

Hi Scott. This is wonderful. Thanks for sharing!

I was curious if your code could also be used to redirect an internal homepage URL to another internal homepage URL. My company just switched from a personal website to Zendesk using the same URL structure and we've noticed that our international clients are having issues getting to their respective homepages. For example, they are typing in help.drewtucker.com/es-mx, but ZD shows an error page because the URL is now help.drewtucker.com/hc/es-mx.

If that isn't possible to fix, we'll just have to message out the new URLs. Thanks for any assistance you can provide.