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.
46 Comments
Say we wanted to redirect all articles of one brand to a new brand is that possible?
Thanks
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.
Hi @..., thanks, would the above solution work across brands, it should from what I've seen but I wonder how SEO might be impacted. We are keen to retain relevance whilst redirecting to our new brand. Any help from the moderator team would be greatly appreciated.
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 everyone i need to redirect from a deleted .pdf
All the methods suggested dont seam to work, Can anyone help?
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...
The instructions on how to redirect for deleted articles, redirect all translations to English. How can I redirect from the deleted articles, to the new article in the language the user has? I tried removing the EN part from the URL, but strangely it made no difference.
Edit: To be super clear what code I'm talking about:
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]; } }
Edit 2: It turns out, removing the en/ *does* work for all languages, it just took a bizarrely long time after publishing to take effect. Whoohoo!
https://YOURSUBDOMAIN.zendesk.com/hc/articles/
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
Hi there,
We are trying: Redirecting a set of deleted articles to new article equivalents
And have put in these codes but they are not working. Can you kindly advise us please?
var oldIds = [“900000500263”];
var newIds = [“900001763763”];
for (var i = 0; i < oldIds.length; i++){
if (window.location.href.indexOf(oldIds[i]) > -1) {
window.location.href = ‘https://gogetmy.zendesk.com/hc/en-us/articles/’ + newIds[i];
}
}
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.
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...
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!
Ho I see why. My code is slightly different. I am not converting from one to one . I just want to redirect any 404 to the main page of the help center
So was using that function below and then also added the corresponding not-found class to the error page. But I am always hitting a "$ is not defined" error... (note my script is loading first and on top of anything else)
So the main idea here is to use the following code to fully load the page before running the script. then if the "
not-found" is detected to redirect to the location set...
But no luck so far.$(document).ready(function() {
if ($(".not-found").length > 0) {
window.location.href = 'https://xxxxx.xx.xxx';
}
});
And
Hi Boris! The reason that you're getting that error is likely related to the templating version that you're using. You can read more about that in this article, but to summarize you will now need to import JQuery into your project if you'd like to use a JQuery function. Just follow the instructions there to do that and then test this out again!
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 Spencer! I haven't seen any reports coming through on our side of issues around this recently. The only "it just doesn't work" or "it stopped working" that I've seen has to do with the switch to v2 templating from v1, but that does not sound like it happened with you. How is the issue manifesting for your team? Are you seeing any errors in the console or failed requests in the network tab?
I also had troubles to make the reroute to standard language work. I noticed it was the jquery request to count the amount of error-page classes. The problem was that the code was outside of the
$(document).ready(function () {
part. Jérémy from Zendesk support mentioned that it needs to be part of DOMContentLoaded so I found that the jquery function could not work because of it not being included somewhere.
We don't have the newest theme from zendesk, he also mentioned that maybe jquery needs to be installed if the theme is a new one. So that might be another error source if someone still struggles at this point.
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 () {
Yes, that's correct. I missed that it wasn't inside.
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
I'm trying to accomplish the same redirect but with forms. for cases where the end user has a direct link to a form, I'd like to redirect traffic from an old form to another. I was curious if the code block works the same:
I added and updated the numbers and URL, but I'm not sure if it isn't working because this snippet or if it isn't working because my theme changes aren't proper.
Is it possible to use this snippet for forms, not just article IDs, or is there a different recipe for forms?
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:
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?
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.
is it expected that the user is directed to a "page not found" when clicking the original link and then the redirect happens after 2-3 seconds? Im hoping for users to not see this as they may think that the article is gone.
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.
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
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!
Please sign in to leave a comment.