带有“ghosted”的链接解析器301重定向
我正在勾勒出程序流程,以找到一种重定向出现在我的内容中的特定链接的方法,并希望在这里寻求一些一般性建议。
这个想法是有一个出现在如下内容中的链接:
www.targetsite.com
其中,重定向到...
www.targetsite.com?affiliate-id=1234
我将维护一个链接列表,其中包含 301 重定向数据库及其相应的重定向 URL,我只是在这里寻找有关如何处理实际执行重定向的后解析器的想法和选项。例如,当用户将鼠标悬停在上例中的链接上时,它应在状态栏中显示为“www.targetsite.com”,而不是带有附加查询字符串参数。
预先感谢您的想法。
这将部署在 WordPress 上并使用 PHP 进行编码。
I'm sketching out the program flow for a means to redirect specific links that appear within my content and wanted to ask for some general advice here.
The idea is to have a link that appears in content like this:
www.targetsite.com
Which, redirects to...
www.targetsite.com?affiliate-id=1234
I will maintain a listing of links which have 301 redirects inside the database, along with their corresponding redirect URL and I'm just looking here for ideas and options on how to handle the post parser that actually does the redirect. For example, when the user hovers over the link in the above example, it should appear in the status bar as "www.targetsite.com", not with the additional querystring parameters.
Thanks in advance for your ideas.
This will be deployed on WordPress and will be coded in PHP.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
事实上,这听起来很简单,而且我过去也这么做过。它涉及三个组件:
基本上,您在每个链接上使用自定义类(“redirect-XXX”)和“rel”属性。所以不是这样:
你会:
JavaScript 需要拦截所有对带有 rel=”cloaked” 的链接的点击,并阻止它们实际上去任何地方。相反,它会将其重定向到服务器上的页面,并对 URL 中的 id(redirect-1 为 id=1)进行编码,以便服务器可以处理它。基本上,JavaScript 会将浏览器发送到
http://mysite.com/externallink.php?site=http://targetsite.com&linkid=1
,并对 URL 进行正确的 HTTP 转义等等。然后服务器端脚本需要根据 linkid 查找链接(站点引用只是向仔细查看状态栏的任何人指出您仍在将它们重定向到同一站点而不是恶意的地方)并使用 301 从服务器端重定向浏览器。
Actually, that sounds pretty straight-forward, and I’ve done just that in the past. It involves three components:
Basically, you use a custom class ("redirect-XXX") and the “rel” attribute on each link. So rather than this:
You’d have:
The JavaScript needs to intercept all clicks on links with rel=”cloaked” and prevent them from actually going anywhere. Instead, it will redirect it to a page on the server and encode the id (redirect-1 is id=1) in the URL so the server can process it. Basically, the JavaScript will instead send the browser to
http://mysite.com/externallink.php?site=http://targetsite.com&linkid=1
, with proper HTTP escaping of the url and all that.Then the server-side script needs to look up the link (the site reference is just to point out to anyone looking closely at the status bar that you’re still redirecting them out to the same site and not somewhere nefarious) based on the linkid and redirects the browser from the server-side with a 301.