开发者

Link parser with "ghosted" 301 redirect

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 b开发者_C百科e coded in PHP.


Actually, that sounds pretty straight-forward, and I’ve done just that in the past. It involves three components:

  1. A database or list of links on the server side
  2. A JavaScript routine on the front end to intercept link clicks
  3. A server-side processor for the redirects.

Basically, you use a custom class ("redirect-XXX") and the “rel” attribute on each link. So rather than this:

<a href="http://targetsite.com?affiliate-id-1234">Link</a>

You’d have:

<a rel="cloaked" class="redirect-1" href="http://targetsite.com">Link</a>

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜