Redirecting traffic from deleted Help Center articles

Have more questions? Submit a request

51 Comments

  • Simon Celen
    Comment actions Permalink

    Hi Aswin,

    In the default Copenhagen theme there is an element with "error-page" class on the error_page.hbs. If you're using an older or customized theme then it may not be there. Open up your error_page.hbs template and add f.e.:

    <span class="error-page"></span>

    If that doesn't help then it's probably not working due to an other issue. Feel free to paste a link to your Help Center and I'll take a look.

    0
  • Aswin Kannan
    Comment actions Permalink

    Thank you, Simon. We are using a customized theme built on top of Copenhagen. Our help center is help.cricut.com.

    0
  • Simon Celen
    Comment actions Permalink

    Hi Aswin,

    Your error_page.hbs file doesn't have the required class I mentioned. 

    The snippet I pasted earlier should work but it's probably better to change the javascript instead:

    var isErrorPage = $("#error-page").length > 0;  // # instead of .

    Note that there may be other issues preventing the redirects to work but this is definitely one of them.

     

    Hope that helps.

    Simon

    0
  • Aswin Kannan
    Comment actions Permalink

    I have made that change in our sandbox, but it doesn't seem to work either. I wish there was an easier way from the Zendesk Guide side. Just a checkbox that says "Fall back on default language for missing translations". Thanks so much for trying! :)

    0
  • Simon Celen
    Comment actions Permalink

    Hi Aswin,

    Could you link me to your sandbox so I can take a look? Thanks

    0
  • Aswin Kannan
    Comment actions Permalink

    Simon - Our sandbox has different themes under construction, so it will be messy. But the change that you have suggested is available in our production now (help.cricut.com). Feel free to take a look again. Thanks a bunch for your help! :)

    0
  • Simon Celen
    Comment actions Permalink

    Hi Aswin,

    I see what's going on, the code should only run on dom ready:


    $(document).ready(function () {
    /* Start of redirecting untranslated articles to English */
    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;
    }
    /* End of redirecting untranslated articles to English */

    //Up Arrow
    // browser window scroll (in pixels) after which the "back to top" link is shown

    ... snip ...

    That should do it.

     

    Simon

    1
  • Aswin Kannan
    Comment actions Permalink

    This is now working perfectly! You are a rockstar! THANK YOU!

    0
  • Erik Johnson
    Comment actions Permalink

    Anyone have trouble seeing these redirects work in Firefox? We just archived a lot of articles, and the redirects work great in Chrome, Safari, etc. but not Firefox. 

    0
  • Alex Litoff
    Comment actions Permalink

    Hi - I am trying to Redirecting all deleted articles to one specific page, but I want that page to just be our help center home page. 

     

    I tried this code snippet, in the JS section. any idea what I am doing wrong? 

    $(document).ready(function() {
    if ( window.location.href.indexOf('articles') > -1 & $(".not-found").length > 0 ) {
    window.location.href = 'https://[mydomain].zendesk.com/hc/en-us';
    }
    0
  • Simon Celen
    Comment actions Permalink

    Hi Alex,

    Could you check that there is a ".not-found" element in your error_page.hbs. These things change and current Copenhagen themes use an ".error-page" element instead.

    If you see an ".error-page" element, change the JS to:

    $(document).ready(function() {
    if ( window.location.href.indexOf('/articles/') > -1 && $(".error-page").length > 0 ) {
    window.location.href = 'https://[mydomain].zendesk.com/hc/en-us';
    }

    I made 2 other small corrections. While a single ampersand works in this specific case, two is better to make sure you get a boolean.

    I also made the first check look for '/articles/' instead of 'articles'. On the off-chance there would be a deleted section named f.e. "My favourite articles" the old check would match.

     

    If it's still not working there may be something else causing the issue. Feel free to pass the link to your Help Center and I'll take a closer look.

     

    Thanks

    0
  • Alex Litoff
    Comment actions Permalink

    Thanks, Simon!

    Still experiencing the issue. Here is the code on the error page. I see both a ".not-found" a ".error-page" element, which both have classes. 

    Here is the link to our help center (note: I unpublished the updates for now, so you won't see these updates in the live code): https://support.virtru.com/

    <div class="container-divider"></div>
    <div class="error-page" id="main-content-skip">
    <h1>{{t 'oops'}}</h1>

    {{#is error 'unauthorized'}}
    <h2>{{link 'sign_in'}}</h2>
    {{/is}}

    {{#is error 'forbidden'}}
    <h2>{{t 'not_authorized'}}</h2>
    {{/is}}

    {{#is error 'not_found'}}
    <h2 class="not-found">{{t 'nonexistent_page'}}</h2>
    <p>{{t 'mistyped_address_or_moved_page'}}</p>
    {{/is}}

    {{#link 'help_center'}}
    {{t 'back_to_homepage'}}
    {{/link}}
    </div>
    0
  • Simon Celen
    Comment actions Permalink

    Hi Alex,

    It looks like there's an issue with your script.js file. At the very bottom there's a script tag that shouldn't be there:

    <script type="text/javascript" src="https://a.opmnstr.com/app/js/api.min.js" data-account="22402" data-user="32484" async></script>

    It causes the entire script to fail, including the redirect bit. If you want to add in an external script it would typically go in the document_head.hbs template instead.

    Also, I didn't see a .not-found class so best to go with .error-page from my snippet.

     

    Hope that does it.

     

    0
  • Aswin Kannan
    Comment actions Permalink

    Hello everyone - Has anyone figured out how to use vanity URLs in Help Center/Guide?

    Ex: help.company.com/offers linking to an article like https://help.company.com/hc/en-us/articles/360081928433-Latest-offers-and-promotions

    Zendesk makes it really difficult to maintain redirects and we have a necessity to create a bunch of these vanity URLs. :(

    0
  • Simon Celen
    Comment actions Permalink

    Hi Aswin,

    It's possible to set up vanity URLs by applying the techniques discussed in this thread. 

    A link to help.company.com/offers will get you a 404 not found error, served by the error_page.hbs template. This template has a "div.not-found" element. In your scripts.js you can detect this element and then redirect the user depending on the current URL.

    $(document).ready(function() {
    if ($('.not-found').length) {
    var path = location.pathname;
    if (path == '/offers') {
    location.pathname = '/hc/en-us/articles/123-article-to-redirect-to';
    }
    else if (path == '/something else') {
    location.pathname = '/hc/en-us/articles/456-other-article-to-redirect-to';
    }
    }
    }

    if you have a bunch of redirects you could use a variable to make it more maintainable:

    var REDIRECT_MAP = {
    '/offers': '/hc/en-us/articles/123-article-to-redirect-to',
    '/foo': '/hc/en-us/articles/456',
    '/bar': '/hc/en-us/articles/789'
    };

    $(document).ready(function() {
    if ($('.not-found').length) {
    var redirect = REDIRECT_MAP[location.pathname];
    if (redirect) {
    location.pathname = redirect;
    }
    }
    }

     

    Hope that helps!

    0
  • Eugenia Pavlovskaya
    Comment actions Permalink

    Hi,

    I'm trying to redirect non-existent articles to our main page, but our JS file doesn't have that line:

    $(document).ready(function() {

    While we do have a custom theme, it is based on Copenhagen and I have just checked JS file in Copenhagen and didn't manage to find it there either. I tried using different combinations, even looking for all mentions of "document", yet nothing similar seem to be present in neither in Copenhagen nor in our custom theme...

    0
  • Alejandro Colon
    Comment actions Permalink

    Thanks, Elliott,

    I used your redirect idea to set up article redirects to simulate an article being in multiple sections without having to duplicate the content.

    How to Include Article in Multiple Sections

    1
  • Nicole - Community Manager
    Comment actions Permalink

    Thanks so much for writing up your tip, Alejandro! 

    0
  • Alejandro Colon
    Comment actions Permalink

    Nicole - Community Manager

    No problem.

    ----------------------------------------------------------------------------------------------------------------------------------

    I actually started a new post with some of the planned tips I intend on writing up. 

    Ranking Tips to be written up

    I am looking for feedback on which ones I should write up next when I have the time. 

    0
  • Jean Cesar Martínez
    Comment actions Permalink

    Hi -

    We support two languages for most of our articles. For the ones we don't we to redirect the user to the same article in the existing language.

    I tried the Redirecting untranslated articles to an existing language section in this article, but:

    I dont see the document.ready function in our helpcenter code so I thought that I had to insert the whole function. I found a spot in the script.js file and put it there. It didn't work. Instead of redirecting to the article with the existing language, is redirecting to the main page.

    Even without the code I inserted, the helpcenter is redirecting to the main page.

    What am I missing?

    I really want to avoid creating the same article in the unsupported language... 

    0

Please sign in to leave a comment.

Powered by Zendesk