Knowledgebase/Help Center Redirection using JavaScript
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.
-
Thanks for sharing this tip and putting all of this together, Scott!
-
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.
-
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?
-
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!
-
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 -
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?
Please sign in to leave a comment.
6 Comments