简体   繁体   English

如何将特定的URL重定向到另一个URL

[英]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. 我需要将页面上的特定链接重定向到与当前链接不同的URL。 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. 该页面为https://gatewayrealtynp.idxbroker.com/idx/roster ,这是我仅需要重定向其中一个代理的“查看活动列表”链接。 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. 我研究并尝试了几种JS方法,但到目前为止没有任何效果。 Here is the code that I've most recently tried: https://gist.github.com/Hope0417/05257b6798d1720bd740b09537a655ee . 这是我最近尝试过的代码: https : //gist.github.com/Hope0417/05257b6798d1720bd740b09537a655ee Putting the same <script> code between the opening and closing <head> tags didn't work either. 在开始和结束<head>标记之间放置相同的<script>代码也不起作用。 When using this code, it redirects the entire "roster" page to the new URL, which is not what I need to happen. 使用此代码时,它将整个“花名册”页面重定向到新的URL,这不是我所需要的。

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. 我也尝试过在<head>标记和结束标记之间使用<meta HTTP-EQUIV="REFRESH" content="0; url=https://gatewayrealtynp.idxbroker.com/i/listings"> ,但是它确实与上面的代码相同。 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> <head>标记之间的代码没有任何作用: <script type="text/javascript"> var oldWesLocation = https://gatewayrealtynp.idxbroker.com/idx/agent/141880/wes-grady; location = https://gatewayrealtynp.idxbroker.com/i/listings; </script> <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). 而且,如果我发错了问题(我对此很陌生),请接受我的歉意。

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 如果您无法直接更新HTML,请将此javascript添加到名册页面

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. 如果您可以在Wordpress网站上运行此javascript代码,它将查找包含术语wes-grady所有链接,然后将这些链接的href切换到您指定的链接。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM