Would like creative URL redirect ideas!

Answered

14 Comments

  • Dave Dyson
    Zendesk Community Manager

    Hi Scott,

    I think you can accomplish this by adding some JavaScript to your old Help Center theme's script.js file.

    If you want to do direct people from specific articles in the old Help Center to specific articles in your new Help Center, I think you could adapt Redirecting traffic from deleted Help Center articles. This article has some step-by-step instructions for editing the code, so it's useful to look at even if you don't end up using their exact method, and there's also an important disclaimer about our ability to support custom code like this. But if you do run into difficulties, you can always ask for help here in the community!

    If you're looking to do a more general redirect of all traffic from the old Help Center to the new one, take a look at the code this user came up with: 

    if(HelpCenter.user.role == "end_user" && window.location.href == 'https://www.home.ca'; )

         window.location.href = 'https://www.google.ca';
    1
  • Samantha Chavez

    Dave Dyson the Website re-direct link is broken. 

    0
  • Dave Dyson
    Zendesk Community Manager

    Thanks Samantha, I've edited my previous comment to include the code directly.

    1
  • Samantha Chavez

    You are fast and a life saver. Thank you!

    0
  • Dave Dyson
    Zendesk Community Manager

    Glad I could help, Samantha!

    0
  • Scott Haugsjaa

    Dave Dyson Oh this is very helpful! I think I'm doing something wrong though. I tried entering the java into my script.js file and it didn't seem to do anything. I basically want any/all traffic, regardless of where it goes on the old site, to auto-redirect to the new site.

    Old Site: https://descohelp.zendesk.com/hc/en-us
    New Site: https://esc-support.fieldedge.com/hc/en-us

    if(HelpCenter.user.role == "end_user" && window.location.href == 'https://www.descohelp.zendesk.com'; )

    window.location.href = 'https://esc-support.fieldedge.com';

    0
  • Samantha Chavez

    Scott Haugsjaa

    I did some tweaking for mine and this works. I put it at the top of the script.js file. You will see a quick page flash and then the redirect. 

    $(document).ready(function() {
      if(HelpCenter.user.role == 'end_user' && window.location.host == 'olddomain.com') {
          window.location.href = 'newdomain.com';
      }
    });
    0
  • Scott Haugsjaa

    Samantha Chavez Thanks, Samantha! I must be doing something wrong, I think. In the image below, you'll see I modified the code using what you provided but modified it to my old/new sites. Any suggestions on what I might be doing wrong or how to fix it?

    0
  • Samantha Chavez

    One thing I did not account for was users who are not signed, which is anonymous by role identification. You are probably experiencing this if you are testing while signed out. I tested with an end user account I use. I am also always signed in for Support, so I forgot to account for that. I am sure there is a more efficient way to handle this if you want all users even internal redirected, for me I am doing work on one help center and want to direct only end users to another help center in the meantime, but need internals to see the hc in the meantime. I am learning deeper usage of JS as I go. Ha!  You can try the below for a quick solution and then play around with removing the if and keeping old domain (window.location.host == 'olddomain.com') portion. 

    $(document).ready(function() {
      if(HelpCenter.user.role == "end_user" || HelpCenter.user.role == "anonymous" && window.location.host == 'olddomain.com') {
          window.location.href = 'newdomain.com';
      }
    });
    0
  • Justin Federico

    Samantha Chavez

    Hello Samantha,

    I am trying to use your code to redirect users from one Zendesk HC to another. I have added the code at the top of the script.js file and changed the domain values but the redirect is not happening. Not sure what the issue might be.

    Doing a trace I am seeing an error in the browser when I have the code added to the .js file. "SyntaxError: Unexpected string"

    0
  • Samantha Chavez

    Justin Federico

    I actually moved my code to the document_head.hbs template at the bottom. I don't remember why, but I think I couldn't get it to work properly in the script.js file. At least I think I had consistency issues. I am not a pro coder so my apologies here! The final version of what worked for me ended up being the below. For me, I needed end users and those not signed in to redirect but wanted agents and admins to still see the old one as I remerged the product brand help centers into one single help center (so I could leverage AB in our platform) and my team still needed to see the old help centers. So you ignore the extra in the if portion.

    <script type="text/javascript">
    $(document).ready(function() {
    if((HelpCenter.user.role == "end_user" || HelpCenter.user.role == "anonymous") && window.location.host == 'oldDomain')
    {
    window.location.href = 'newDomain';
    }
    });
    </script>
    0
  • Justin Federico

    Samantha Chavez

    Thanks. I tried your code as you described but there is no redirection occurring. I too would like agents to be able to get to the old HC so there was nothing to change but the domains.

    I used the code that Dave provided in the original comment and I do see the redirect. The only drawback here is that there is a flash of the old page.

    I removed the content so the screen flash is blank. This may suffice for now. Thanks again.

    0
  • Scott Haugsjaa

    Is it possible, when the user has successfully been redirected, that the new page they land on starts them with the cursor automatically in a search field? Basically, so they could just start typing/searching for something?

     

    It looks like I could, using the method here: https://stackoverflow.com/questions/10894638/how-to-set-cursor-to-input-box-in-javascript

    But, being honest, this is above my head. Anyone have any suggestions on how to apply that information here, using the search box on this page? https://esc-support.fieldedge.com/hc/en-us

     

    0
  • Tipene Hughes
    Zendesk Developer Advocacy
    Hey Scott,
     
    One way you could go about this is adding the autofocus attribute to the input element you'd like to be in focus. Here's a link to the mdn docs which goes in to a bit more detail: 
    Feel free to reach out with any questions!
     
    Tipene
     
    0

Please sign in to leave a comment.

Powered by Zendesk