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
Sawako Kubo
Hi
This redirecting code was working just fine, but I just found out it is not working now. When I access the old page, 404 page shows up.
I added the new and old ID in the script today, but I didn't change other parts of the code.
0
Greg Katechis
Hi Sawako! I took a look at your help center and it looks like you aren't following the instructions in the article correctly. It states that you need to add the script before the JQuery function runs, however you have it after that line. Please move that above and let us know if that resolves it for you.
0
Sawako Kubo
Greg Katechis
Thank you for checking my code!
The following code is already written right above the redirecting code. Could you see the attachment?
0
Greg Katechis
Right, which is the issue...it's supposed to be above that and you have it below it.
0
Sawako Kubo
Greg Katechis
I moved the following code, but it still doesn't work.
$(document).on("click", function() {
$(".share-label").attr("aria-selected", "false");
});
0
Greg Katechis
0
Sawako Kubo
Greg Katechis
no errors![](/hc/user_images/6M3qMCkE9xJ034SJDlwJBQ.png)
0
Sawako Kubo
Greg Katechis
Now it's working! thank you for helping me.
The problem was in other part of code.
0
Product Team
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.
0
Josh H
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.
0
Greg Katechis
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!
1
Ani Samajpati
Hi Greg Katechis,
Please take a look at my code as well. I have copy-pasted part of it here. Reading thru the comments, I have added it within the ready function. I don't see any jquery code above my code. Can you please help me understand why the code isn't working. As soon as I click on the old article link, I keep hitting this zendesk auth page.
0
Spencer Fleury
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?)
0
Philip Addison
Does this process work for archived articles as well, or only for deleted articles?
0
Elizabeth Brown
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
0
Ani Samajpati
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
0
Wilson Ho
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.
0
David Morton
Julio H Regarding 301 redirect Early Access Program:
I applied through the google form a few days ago and it said someone would contact me about getting on the EAP but I haven't received any email acknowlegement. Do you know anything about the EAP?
0
Madison Hoffman
Wilson Ho, unfortunately I don't think anything in this tutorial would cover that use case. In method 3, you specify unique URLs to redirect. But looking at the bigger picture, I would question the UX of automatically redirecting a broken link to point to your home page. As an end user that could be a confusing experience. Would it maybe be better to customize the error state template to make it easy to get back to the home page instead? Could you share a little more about your use case?
David Morton, I'll ask the Guide team to look into this!
0
Stacie Loving
Hello,
I'm using the Copenhagen theme (2.19.4) and nowhere in the script.js file do I see anything similar to:
Do I just add the redirect to the file? Does it need to be at the top of the file or is it ok to append to the bottom?
Thanks
0
Sally Anne Dishong
We are considering using this edit in our theme code. I have a related question...does anyone have a tool we can use in Zendesk Help Center to find broken links?
0
Sally Anne Dishong
Also, does this code work for archived articles as well as deleted articles?
0
Gab
That code can be found on line 5 of the Copenhagen theme.
Hi Sally,
I'm afraid there's is no way to check for broken links.
You can also check on this Community post here where there's been a few people asking about it as well: https://support.zendesk.com/hc/en-us/community/posts/115007417707-Managing-Links
Furthermore, the examples provided in this article are for deleted articles.
0
Sally Anne Dishong
Thank you, Gab. So...the examples are for deleted articles. We generally do not delete articles as our practice. Is there a similar way to redirect archived articles as well?
1
Gab
For the articles that are in draft or archived, they'll still be visible for you. However, the end-users won't be able to access them. If an end-user opens an article URL that has been archived, they'll see the "oops" error page on your Help Centre. This page is built on the error_page.hbs template that you'll find on the live theme in Guide. If a user opens an article URL that has been unpublished, they'll be asked to authenticate (if they're not logged in) and then get the "oops" page. In this case, there's no option to redirect them to a different URL as they won't be able to see this article. You might want to publish these articles and then add a custom code to the template to redirect the users to another article.
Hope this helps!
0
Peter Cimring
Hi
Can anyone advise how we could redirect a URL in Zendesk Guide to a page on an external site? (We have certain pages that now live elsewhere.)
We are looking to implement a 301 Redirect (not a JS-based flow).
Thanks!
0
Tammy Paul
I just discovered that this only seems to work for logged in users. Is it supposed to work when login is not required for the help site?
0