HopeR
HopeR

Reputation: 1

How to redirect specific URL to another URL

I need to make a specific link on a page redirect to a different URL than what it currently directs to. The page is https://gatewayrealtynp.idxbroker.com/idx/roster and it's the "View Active Listings" link that I need to redirect for just one of the agents. I should note that I do not have access to the root files.

I have researched and tried several JS methods, but nothing has worked so far. Here is the code that I've most recently tried: https://gist.github.com/Hope0417/05257b6798d1720bd740b09537a655ee. Putting the same <script> code between the opening and closing <head> tags didn't work either. When using this code, it redirects the entire "roster" page to the new URL, which is not what I need to happen.

I've also tried using <meta HTTP-EQUIV="REFRESH" content="0; url=https://gatewayrealtynp.idxbroker.com/i/listings"> between the opening and closing <head> tags, but it does the same thing as the above code. This code between the <head> tags doesn't do anything: <script type="text/javascript"> var oldWesLocation = https://gatewayrealtynp.idxbroker.com/idx/agent/141880/wes-grady; location = https://gatewayrealtynp.idxbroker.com/i/listings; </script>

Thank you in advance for any suggestions/guidance on this. And, please accept my apologies if I've posted my question incorrectly (I'm very new at this).

Upvotes: 0

Views: 244

Answers (1)

Maneesh
Maneesh

Reputation: 408

Based of your reply to my comment I now understand what you are trying to achieve.

If you cannot update the HTML directly, Add this javascript to the roster page

let wes = document.querySelectorAll('a[href*="wes-grady"]');
wes.forEach(link => {
   link.href = 'https://gatewayrealtynp.idxbroker.com/i/listings';
});

If you can run this this bit of javascript on the Wordpress site, it will look for all the links that contain the term wes-grady and then switch out the href of just those links to the one you specified.

Upvotes: 1

Related Questions