How To Redirect Pinned Topic To External URL?

AI-generated summary

The user frtt asks how to redirect a pinned topic to an external URL in Discourse. They tried using permalinks and JavaScript, but the redirect only works after reloading the page. JimPas suggests a workaround: instead of redirecting the topic URL, create a post with the external link, pin it globally, and optionally close the topic. This keeps the external link visible at the top of the topic and avoids redirect issues. frtt requests clarification, and JimPas explains the steps in detail.

Hi, I want to display a pinned topic on my forum that when clicked will redirect to an external URL.

I have tried setting this up in the Permalinks settings, and with this javascript code

    if(window.location.href === "https://x.com/1") 
    {
       window.location.replace("https://y.com/");
    }
</script>

and in both cases it doesn’t work when the topic is clicked on from forum. When clicked it loads the normal topic url.. but then if you reload the topic page while already on it, it will then redirect to the external URL :thinking:

how can i make it work correctly, so that when someone clicks a certain topic it redirects to different URL?

Thank you, I’m enjoying discourse so far! :slight_smile:

It looks like you’ll have to change the URL directly for the topic itself in the categories section. Then it should go directly to the external URL - also saving the step of clicking and loading the topic, then clicking on it a 2nd time. Hopefully someone from Discourse will chime in if this would break something in the way categories are listed - and their respective URLs.

Hey, I apologize but I don’t quite understand what you mean. would you mind explaining again the steps to follow?

Sure, no problem.

  1. First go to the topic you want to have a redirect to external URL in;
  2. Create a post with whatever text you want along with the external URL;
    2a (Optional: If there is a graphic title in the external URL, you can Onebox the URL in your first post which will provide a visual aide to your external link.)
  3. Pin that post globally (it will always stay at the top of the lists of posts in that topic); and as an option,
  4. If you do not want/expect any new posts in that topic, Close the topic as well.

This way, you are not likely to break any links to the topic within Discourse, and you have your external URL always at the top when users go to that topic.
Edit: Pinning it globally should also keep that topic at the top of the list when a user clicks on “Latest” as well. :wink: