If you've deleted articles from your help center, you may have noticed that users occasionally still attempt to access the URLs associated with these articles. No matter the source of such traffic, you can automatically redirect users visiting these URLs to more valuable pages.
Accessing your help center's custom JavaScript file
The solutions contained within this article may affect Google search rankings since they contain Javascript redirects. For this reason, they may not be suitable for long-term or large-scale deployment.
To implement the solution, you must first access your help center's JavaScript file:
- Sign in to Zendesk Support as an administrator. Next, click the Zendesk Products icon (
) in the top bar, then select Guide.
- In the top right corner of Zendesk Guide, select Guide admin.
- Click the Customize design icon (
) in the sidebar.
- Click Customize on your theme.
- Click, Edit code.
- Click the script.js file.
See the GIF below for a visual example of accessing the JavaScript file:
This article includes several solutions that, in most cases, can redirect traffic:
- Example 1: Redirecting a set of deleted articles to new article equivalents
- Example 2: Redirecting untranslated articles to an existing language
- Example 3: Redirecting all deleted articles to one specific page
- Example 4: Generalizing or specifying which articles (or community posts) redirect to a particular page
Example 1
Example 2
Example 3
Example 4
Example 1: Redirecting a set of deleted articles to new article equivalents
In this example in which, a help center has a set of old, deleted pages, each corresponding to a new page to which we are redirecting.
Within the first few lines of the JavaScript file, you will see a line reading:
$(document).ready(function() {
Insert the following code directly above that line:
var oldIds = ["217352077", "216552968"];
var newIds = ["216553098", "216552958"];
for (var i = 0; i < oldIds.length; i++){
if (window.location.href.indexOf( oldIds[i]) > -1) {
window.location.href = 'https://YOURSUBDOMAIN. zendesk.com/hc/en-us/articles/ ' + newIds[i];
}
}
Before saving it, you must customize a few things about this script. The first part of the code you'll edit is here:
var oldIds = ["217352077", "216552968"];
var newIds = ["216553098", "216552958"];
This is a list of the old article IDs and new article IDs. Add your article IDs here. To find an article ID, view the article in your browser (or the URL from your analytics platform). The URL will look similar to this:
https://[YOURSUBDOMIAN].zendesk.com/hc/en-us/articles/203664386-Help-Center-guide-for-agents-and-end-users
In this case, the article ID is "203664386".
To redirect properly with this solution, the article IDs must be at the same position within the array. In this case, an article whose URL contains "217352077" will now redirect to "216553098". And an article containing "216552968" will now redirect to "216552958".
Be sure to keep these IDs wrapped in quotes, as seen above, and separated by a comma in each case. So if you added a new set of redirects, it would look like this:
var oldIds = ["217352077", "216552968", "216552902"];
var newIds = ["216553098", "216552958", "216552944"];
Next, you will have to edit the URL in this line:
window.location.href = 'https://YOURSUBDOMAIN. zendesk.com/hc/en-us/articles/ ' + newIds[i];
Make sure you use your subdomain, or alternately, use your entire help center URL as it normally appears in your help center if it is white labeled to your URL. Do not remove the end of the line, where it reads "+ newIds[i];". This is how the loop appends your new article ID to your URL. The code will fail without it.
Example 2: Redirecting untranslated articles to an existing language
In this example where you have help center content in multiple languages. Let's say all of your contents exist in English, but only some of them exist in French and German. Users who try to access those articles in French or German will get an error page. This code allows redirects them away from the error page back to the existing English-language article:
var notDefaultLanguage = window.location.href.indexOf('/en-us/') == -1;
var isArticle = window.location.href.indexOf('/articles/') > -1;
var isErrorPage = $(".error-page").length > 0;
if ( isArticle && notDefaultLanguage && isErrorPage ) {
var newURL = window.location.href.replace(/(.*\/hc\/)([\w-]+)(\/.*)/, "$1en-us$3");
window.location.href = newURL;
}
In this example, only a small amount of customization needs to be done. If your default help center language isn't English, you can replace that language. In the code, you'll see "en-us" appear in two places:
var notDefaultLanguage = window.location.href.indexOf('/en-us/') == -1;
and
var newURL = window.location.href.replace(/(.*\/hc\/)([\w-]+)(\/.*)/, "$1en-us$3");
Replace "en-us" in these two lines with your default language code. You can find your default language code in the URL for your main articles. For example, a URL for a French-language help center page will look like
https://[YOURSUBDOMAIN].zendesk.com/hc/fr/articles/214943538
with "fr" representing the country code.
Example 3: Redirecting all deleted articles to one specific page
In this example, a help center redirects all deleted articles (not including community posts) to a particular article.
Within the first few lines of the JavaScript file, you'll see a line reading:
$(document).ready(function() {
In this case, insert the following code directly below the line. Important note, inserting the above (as with the previous example) will not work for this example:
if ( window.location.href.indexOf('articles') > -1 && $(".not-found").length > 0 ) {
window.location.href = 'https://[YOURSUBDOMAIN].zendesk.com/hc/en-us/articles/216553068-error-redirect';
}
You'll need to customize the URL in this script before saving it. Replace it with the article URL you want your help center to redirect to.
This solution will only work if we ensure a ".not-found" class exists on your error page. So let's add one.
On the grey bar where the "JS" link appears, click on the "Home Page" link. Find and select "Error page" in that dropdown. In the error page, you'll find an area starting with the code {{#is error 'not_found'}}
. It will look something like this:
{{#is error 'not_found'}}
<h2>{{t 'nonexistent_page'}}</h2>
<p>{{t 'mistyped_address_or_moved_page'}}</p>
{{/is}}
You'll want to add a new class to the h2 element or any element within the 'not_found' #is
tags so that it looks like this:
<h2 class="not-found">{{t 'nonexistent_page'}}</h2>
Now you have all the elements in place that you'll need for a generally deleted article redirect.
Example 4: Generalizing or specifying which articles (or community posts) redirect to one specific page
You can get more specific or general with this solution by customizing the if statement. For example, to redirect from any deleted article or community post, change the if statement to:
if ( $(".not-found").length > 0 )
Alternately, to only redirect deleted articles that have the word "buttermilk" in the title, change the if statement to:
if ( window.location.href.indexOf('buttermilk') > -1 && $(".not-found").length > 0 )
Unlike the first solution presented, these solutions will briefly show the error page, then redirect to the new page. This is because we are using JavaScript to search for an element within the page, and to do that, we must first wait for the page to load.
47 Comments
So we've been using this code for a long time, and today it suddenly stopped working. We haven't modified our template in any way recently, other than to add more articles to var oldIDS and var newIDs. Has anyone else had this experience?
Hi Josh! I took a look at your help center and it is pretty heavily customized, so I'm assuming that's the reason that you're not seeing it. I would recommend talking to the devs that built that to see how they developed it to see if they can steer you in the right direction. As it stands, it really wouldn't be possible for me to tell you how to proceed in this situation, so they will be your best bet!
Boris Fernandez I just double checked my setup, and it's working currently with the above example code, even without this line in the script.js:
$(document).ready(function()
One thing I can think of that might be causing this to not work as expected, is that you may need to check that your script.js file is valid code syntax. If it has a syntax error, it will break the file and not fire the contents correctly. I can see that GoGet Support up there for example, if I try to visit the URL they are trying to redirect to, I can see the script.js has a syntax error on line 5, which is probably why this is not working for them. You can see in the dev console, if the script.js throws an error when the page loads.
Do archived articles change the analytics in Explore?
For instance, if I have a report that shows the total # of articles views and I remove one article that had 100 views, does the report show the total #of article views drop by 100? Or does it keep track of all article views, regardless of whether they are archived? How about deleted?
Hi,
I added the code as suggested, and it is redirecting well.
The only issue I'm facing is the "flickering". I see the "old" article content for some milliseconds, and then it redirects to the new article.
Any solution to resolve this?
Thanks
So sad there isn’t a good solution for this after all these years. It’s been requested so many times. Even HelpScout with so much less functionality has a better redirect system.
How can I setup redirects from an article on a different brand? Also, following this guide isn’t working for me; it’s requiring a login when accessing the old article because it’s trying to access Zendesk admin for that article
CJ Johnson cannot make it work. Actually no error from the JS on the dev console. Not sure what I am doing wrong.
When you say you do not need the function, how do you input the code in the script.js ?
I tested the error_page.hbs also to see if I could miss something but nothing off there too...
Everything looks pretty straight forward though...
Greg Katechis
no errors
Hello,
I would like to redirect untranslated articles to the default language article.
For example, my default language is English and I have French translation. If the French translation does not exist for an article, the user who selects French, is currently redirected to the French home page. But I would like him to be redirected to the English article.
I tried the code bellow but it doesn't change anything...
Yes, that's correct. I missed that it wasn't inside.
Hi, we followed the instructions in the article above to redirect the untranslated article to the original article in English. However, it seems it's not working: this is an article in English that is not translated in German, but if you switch the language to German it redirects you to the home page instead of showing yout the article in English: https://zakeke.zendesk.com/hc/en-us/articles/4514828443932-Test-for-fallback
What's wrong?
Thanks
Carlo
Hey Greg Katechis,
I look in our script.js file and it doesn't have the below line:
If that's missing, can we simply add it? Do you know which line would be the best place to add it? Thank you.
Hi David,
Articles still have the same ID
If your articles still have the same ID, then you need 1 redirect line.
Articles with changed IDs
You will need a single redirect line for each article if your articles no longer have the same article ID.
Hi Elizabeth Brown and Philip Addison,
While you are waiting for Zendesk team to respond, I can share my experience here. For me, the code only worked when I archived the old articles. "Unpublishing" the old article led to a redirect to an authentication page and not to the new article.
I haven't tried deleting an article and redirecting it yet, so cannot comment on this part.
Best,
Ani
Hello @...,
This article's information with some changes to fit your use case is the best documentation we have available for this ask. I'll reach out to our moderator team to see if they can offer son insight into making these changes. We'll also share this post in our weekly digest so others can share that advice on how to accomplish this.
Best regards.
Here's what mine looks like:

The error.hbs template would also require that you put the code inside some HTML script tags, as the template is a Handlebars file. In script.js, this isn't necessary, since it's a javascript file.
Edit: Also, for whatever reason, it took like a solid half hour to hour for the code to start working when I deployed it the first time. I posted higher up in the thread about it, I kept trying to "fix" it when it turned out it was already working and it I had just stopped fussing at it, it would've started working after a bit. Just throwing that out there because I forgot about the weird long wait and it made me think the code didn't work either!
Hello—I've had success with this workaround on the article level, but is there any way to make it work for anchor links? As our Help Center grows and evolves, the internal structure of the articles will often change, and headers (which have those anchors) will be deleted or moved to other articles, etc. But there are still links out there in the wild that point to these anchored links, and I'd like to be able to ensure they are redirected to where they need to be.
(Also, why is this so challenging in Guide? Every other CMS I've worked with supports redirects a lot more efficiently than this. Are there plans to enhance this?)
To answer my question above, you can accomplish redirecting from one form to another with the same method and a few adjustments:
Notes about snippet above:
Hi Zendesk team - does this option work with archived articles at all? or do I have to delete an article before I can go through the process of redirecting the URL?
I'd prefer archiving, just in case I want to re-work content later.
Please advise?
Cheers
E.A. Brown
Honestly, I am in awe that the Zendesk product team considered this release ready.
It's unreasonable to expect your users—help docs and technical writers—to have to know JavaScript to configure basic redirects for duplicate or obsolete pages. This is functionality that should have had a full WYSIWYG decade ago in the platform.
I am trying to redirect all broken links to my home page, would method 3 work for this? I tired and just entered in the homepage address instead of a specific article but its not working.
Bailey McWhorter - I believe Julio had Google Translate enabled when he took the screenshot, and while Google does it's best, it doesn't always get the technical terms for Explore quite right. which is why the name of the attributes aren't matching up exactly. Interaction ID should be Engagement ID and Item ID should be Article ID.
Aakash Gill - while I don't have a solution for the page flickering due to redirects, perhaps others have found a way help mitigate this and can chime in with anything custom they have done!
Thanks for your feedback.
Archived articles will continue showing and be counted in Explore. Only the team publishing dataset.
In the other dataset, for example, Knowledge base. In the viewed article metric, you will not be able to see the title or information about delete or archived articles, but you will be able to see the number of times those articles were viewed.
Adding the metric interaction ID, I can see the ID of those deleted or archived articles.
For more information, please visit: Metrics and attributes for Zendesk Guide
I hope it helps!
Greetings.
Julio H, thank you. I don't see interaction ID or Item ID in Guide: Knowledge base.
Right, which is the issue...it's supposed to be above that and you have it below it.
It seems that your concern have been resolved on a ticket that have been submitted. The problem was with the JQuery request to count the error-page classes. But it needs to be inside of $(document).ready(function () {
Greg Katechis
Now it's working! thank you for helping me.
The problem was in other part of code.
Please sign in to leave a comment.