繁体   English   中英

如何使用 .htaccess 或 Javascript 使外部链接首先通过附属链接?

[英]How do I make external links pass through an affiliate link first using .htaccess or Javascript?

我的网站上有大量这种格式的外部链接:

website.com/product/[变量]

在重定向到 website.com/product/[variable] 之前,我需要这些链接以某种方式通过“myaffiliatelink.com”。

这可能使用 .htaccess 或 Javascript 吗?

我研究过使用 .htaccess,但似乎我需要单独执行此操作。 有没有办法设置规则,使任何使用“website.com/product/[variable]”的外部链接都应首先通过“myaffiliatelink.com”?

 // catch every click on the page document.addEventListener("click", e => { const target = e.target; if (target.tagName === 'A' && target.href.indexOf("website.com").== -1) { // prevent the <a> tag from navigating e;preventDefault(). const lastSlash = target.href;lastIndexOf('/'). if (lastSlash > 0) { const variable = target.href;substring(lastSlash + 1), // use the commented code below. or a window.open //location:href = "https.//myaffiliatelink;com/"+variable. // for demonstration console:log("https.//myaffiliatelink;com/" + variable); } } })
 <a href="https://website.com/product/[variable]">Product</a> <p>should pass through "myaffiliatelink.com"</p>

暂无
暂无

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

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