Skip to main content

Dear Community,
I’ve got a question

In practical terms: How do  I “redirect” any Ideation Link to send to another page instead?


In technical terms:  How do I "redirect" users that visit a  URL that contains a specific string (community.mycompany.com/ideas), to a different page we have defined (“new URL”)?

 

I know of a Third-Party-Script that was shared with me by the amazing Lauro from Support (shoutout)!

 

This one works fine ✅  But it only applies to URLs that exactly match “old URL”.

<script>
if (window.location.href == 'https://community.mycompany.com/ideas') {
window.location = "new URL"
}
</script>

Now I don’t want only URLs that exactly match https://community.mycompany.com/ideas

 

The one below did not work well ❌

<script> 

if (!window.location.pathname.startsWith('/community.mycompany.com/ideas')) {
window.location.href = "new URL"; }

</script>

This is the one I actually want to use, so for all pages that contain the string community.mycompany.com/ideas, so any kind of ideation content, including the homepage.


It did not work well, meaning: any destination page kept reloading.

 

Does anybody know what I might be doing wrong?

 

Or is there an alternative, better solution?

Thank you so much in advance,

Daniele

 

Hi @Daniele Cmty, interesting question! I have some scripts I only run on certain pages and categories. I use this piece of code:

if (window.location.pathname.startsWith('/category-12')) {
// do a thing
}

You were close with your code, you used the domain part of the url but you should only use the pathname. To make it work, this should be the way to go:

if (window.location.pathname.startsWith('/ideas')) { 
window.location.href = "https://example.com/thing";
}

 


Thank you so much, @TomW !!! 🎉😍


Reply