Blog

How to Redirect a Knowledge Base Page

  • 5 January 2023
  • 3 replies
  • 165 views

Userlevel 4
Badge +4

Redirecting a Knowledge Base (KB) page allows you to add flexibility to your articles or forms easily. For example, imagine you've already created a privacy policy page on your company's website. Instead of recreating this page in a KB article within Kustomer - you'd like to redirect the customer to your existing page. We can easily avoid this hassle by adding a single file to your KB theme.

 

Before starting, while you can configure a redirect without knowing how to code, we will add and modify a few lines of simple code to your theme. The process is very straightforward, and you'll be redirecting articles in no time!

 

You can skip to the next section if you already know which theme you want to edit. To ensure we are making changes to the theme currently being used by your knowledge base, navigate to Settings > Knowledge Base > Configuration. At the top of this page will be a brand selector with a dropdown containing all the brands in your Kustomer instance. Double-check the brand here, making sure the brand you wish to make updates to is selected. Next, look at the "Theme" section. The theme selected currently is the default theme for the brand you selected; note the name, as this is the theme we will be updating.

 

Once you know which theme needs to be updated, navigate to Settings > Knowledge Base > Themes and open the theme we found in the previous section. A preview of your current theme will load in the visual editor, go ahead and click "Create New Draft" at the top of the preview pane. For the changes we will be making, we will need to open the code editor by clicking the menu button (three dots) then select "Go To Code Editor" from the menu that appears.

Note: If you see "Create Draft" instead of "Save Draft" create a new draft before opening the code editor.

 

You should now see a blank page displaying "No file selected." You can find all the files that make up your theme on the right of the code editor. We won't be editing any of these, but for context, there are three types of files:

  • Pages - the different pages that make up your Knowledge Base (Articles, Homepage, etc.)

  • Components - Components are files are used to build pages and can be pulled into different pages.

  • Globals - Files accessible by the Knowledge Base globally, meaning any page can access these files. We will be creating a global file to redirect our pages.

 

Click "Add Files" at the top of the Theme Files pane to create our redirect. When the "Create Theme File" window appears, create a file using the following options:

 

  • Theme Target: Global

  • File Name:  redirect

  • File Type: JS

Note: Do not add an extension to the file name; the last option will add the file type.

 

Scroll down to the Globals section of the Theme Files pane and open our newly created redirect.js file. In the new file, paste the following code:
 

if (window.location.href.includes("leave-this-page")) { window.location.href = "https://gotothispage.com" };

 

Next, we will edit the code to redirect a KB article.

 

In the parenthesis after window.location.href.includes (first line), replace the text inside the quotation marks with the slug of the article you wish to redirect. You can find the slug for an article on the article editor page at the top of the article. 

 

Then replace the https://gotothispage.com with the URL of the page you will redirect the article.

 

Once you’ve updated the code in the redirect.js global file, save and publish the draft. Now preview your theme and navigate to the article you configured the redirect for. When the article loads, you should be redirected to the URL you entered.

 

If you are not redirected, double-check the theme to ensure you have published your changes. Next, check the code in the redirect file.

 

Closing

Redirects can be used for forms or whole categories by changing the text after “includes” to the form’s slug or the categories subdomain. Additionally, if you need multiple redirects, you can paste the same code under your initial redirect to redirect as many articles as needed.

 

If you run into any issues or need assistance configuring your redirect, reach out to Kustomer support via chat or email at support@kustomer.com any time!


3 replies

Badge +2

@nate.skiles Hey there! I’m trying to work through this article, but unfortunately, all of the screenshot drops have expired so the links are dead. 

Is there any way to embed the images into the text instead of the external links that expire? 
https://kustomer.d.pr/nXz9FAhttps://kustomer.d.pr/sBgH6P, and https://kustomer.d.pr/8tRMOa are not populating anything and I’d love to check my work. 

Also, I’m trying to determine the use case of redirects here. This post says:

“For example, imagine you've already created a privacy policy page on your company's website. Instead of recreating this page in a KB article within Kustomer - you'd like to redirect the customer to your existing page.“

But when I read the process steps, it seems to describe redirecting a KB article to another link. Using the privacy policy example, you would still need to have a KB URL set up (even if there was no text), and then you create the redirect from the KB privacy policy article URL to the website privacy policy URL? Is that correct? 

Hi @casey_m, thanks for bringing this to my attention, and apologies for any inconvenience! I’m working getting those images updated and will ping you here once fixed.

Regarding your second point, you wouldn’t necessarily need the page you are redirecting to exist in Kustomer. For example, if you wanted help.zzz-nate.com/privacy-policy to redirect to shop-zzz-nate.com/privacy - the article wouldn’t need to be created in a KB. While it’s not very likely that a customer would find the first URL without an article created, if someone ever navigated to that URL, they would be redirected to the external site.

Creating an article allows something like a privacy policy to show up in searches, but have the content hosted externally.

Badge +2

@nate.skiles Thanks so much for your reply!

Yes, we were hopeful to have the privacy policy show up in searches and be a result for article deflection (so we would need a KB article “placeholder”). I appreciate you confirming!

Reply