Recent searches


No recent searches

Would like creative URL redirect ideas!

Answered


Posted Oct 01, 2021

Hey guys!

My company has switched to a corporate Zendesk account with various Guides. Long story short, we have an old Guide on a different url/account that a lot of our users still use (even when we try to get them to the new help center).

Is there a way to setup a redirect when someone uses the old URL to automatically point them to the new Guide url/account?

It doesn't -feel- like a normal redirect process and if it is, I'm not sure where to start with it.

Any suggestions/ideas/thinking outside-the-box?


1

15

15 comments

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


@... the Website re-direct link is broken. 

0


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

1


You are fast and a life saver. Thank you!

0


Glad I could help, Samantha!

0


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


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


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


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';
  }
});

1


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


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


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


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


image avatar

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


I was able to get this working via this code and added it to the script.js file.

  if (HelpCenter.user.role === "end_user" || HelpCenter.user.role === "anonymous") {
  var communityRedirectUrl = 'addredirectDomain';
  var supportRedirectUrl = 'addredirectDomain';
    var currentUrl = window.location.href;

  if (currentUrl.includes("https://[yourZendeskDomain].com/hc/en-us/community")) {
      window.location.href = communityRedirectUrl;
  } else if (currentUrl === 'https://yourZendeskDomain].com/hc/contributions/posts?locale=en-us' ||
             currentUrl === 'https://yourZendeskDomain].com/hc/en-us/subscriptions') {
      window.location.href = communityRedirectUrl;
  } else if (currentUrl === 'https://yourZendeskDomain].com/hc/en-us/articles/preview' ||
             currentUrl === 'https://yourZendeskDomain].com/hc/en-us/categories/preview' ||
             currentUrl === 'https://yourZendeskDomain].com/hc/en-us/sections/preview') {
      window.location.href = supportRedirectUrl;
    }
  }

1


Please sign in to leave a comment.

Didn't find what you're looking for?

New post