Knowledgebase/Help Center Redirection using JavaScript


  • Nicole Saunders
    Zendesk Community Team

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

  • Jennifer Rowe
    Zendesk Documentation Team

    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.

  • Eivind

    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? 

  • Scott Havard

    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!

  • Eivind

    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:

    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 = '';
    var helpCentreArticles = 'articles/';
    var helpCentreCategory = 'categories/';
    var helpCentreSection = 'sections/';

    var secondaryHelpCentreURL = '';

    //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
  • Aswin Kannan

    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

    Can we create a redirect and point it to this article?

  • Drew Tucker

    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, but ZD shows an error page because the URL is now

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


Please sign in to leave a comment.

Powered by Zendesk