Question
I have deleted articles from my help center. Can I redirect traffic from my deleted help center articles?
Answer
Yes, 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
To implement these solutions, access the JavaScript file of your help center:
- 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.
Check the sections below for examples on how to implement common redirect workflows:
- 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: Redirecting a set of deleted articles to new article equivalents
In this example, the 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() {
window.addEventListener("DOMContentLoaded", () => {
}
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, edit the part of the code, which lists the old article IDs and new article IDs:
var oldIds = ["217352077", "216552968"];
var newIds = ["216553098", "216552958"];
Add your article IDs instead of the ones above. To find an article ID, view the article in your browser. 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 the URL above, the article ID is 203664386
.
To redirect properly with this solution, old and new 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
. The article containing 216552968
will now redirect to 216552958
.
Keep these IDs wrapped in quotes, as seen above, and separated by a comma in each case. It would look like this:
var oldIds = ["217352077", "216552968", "216552902"];
var newIds = ["216553098", "216552958", "216552944"];
Next, edit the URL in this line:
window.location.href = 'https://YOURSUBDOMAIN.zendesk.com/hc/en-us/articles/ ' + newIds[i];
Use your Zendesk 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: "+ 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, help center content exists in multiple languages. If all your content exists in English, but only some of it exists in French and German. Users who try to access those articles in French or German will get an error page. This code redirects the visitors 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, replace that language. In the code, en-us
appears 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. 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 the example below:
https://[YOURSUBDOMAIN].zendesk.com/hc/fr/articles/214943538
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() {
window.addEventListener("DOMContentLoaded", () => {
}
In this case, insert the following code directly below the line. Important note, inserting the above 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';
}
In this script, replace the URL with the article URL your help center will redirect to.
This solution will only work if we ensure a .not-found
class exists on your error page.
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 like this:
{{#is error 'not_found'}}
<h2>{{t 'nonexistent_page'}}</h2>
<p>{{t 'mistyped_address_or_moved_page'}}</p>
{{/is}}
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>
Example 4: Generalizing or specifying which articles (or community posts) redirect to one specific page
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 it uses JavaScript to search for an element within the page, which needs to load first.
57 comments
David Halewood
Say we wanted to redirect all articles of one brand to a new brand is that possible?
Thanks
0
Devan La Spisa
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.
0
David Halewood
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.
0
Kay
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.
0
James May
Hi everyone i need to redirect from a deleted .pdf
All the methods suggested dont seam to work, Can anyone help?
0
Jules
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...
0
CJ Johnson
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/
0
Carlo Dalessandro
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
0
GoGet Support
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];
}
}
0
Boris Fernandez
1
CJ Johnson
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.
1
Boris Fernandez
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...
1
CJ Johnson
Here's what mine looks like:
![](/hc/user_images/k2NEwffQuL8LEoYG_Q-cuQ.png)
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!
0
Boris Fernandez
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
0
Greg Katechis
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!
0
Spencer Fleury
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?
2
Greg Katechis
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?
0
Sebastian
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.
0
Dane
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 () {
0
Sebastian
Yes, that's correct. I missed that it wasn't inside.
0
Wasabi
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
1
mfg
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?
0
mfg
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:
0
Bailey McWhorter
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?
1
Dinos Papoulias
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.
1
Peter F
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.
0
Julio H
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.
0
Bailey McWhorter
Julio H, thank you. I don't see interaction ID or Item ID in Guide: Knowledge base.
0
Aakash Gill
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
1
Sabra
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!
0