CMS & WordPress
First off, sorry for my bad English
One of my clients needs something special but I have no clue on how to do it.
I have a problem with wordpress redirect function, or in other words, I don't know how to implement such functionality .
Senario: several posts have links to external resources. On page load I want to parse for links, rewrite the link target to post title and finally 301 redirect to its destination page.
post title: the post
post content contains: <a href="http://external.com/page1.htm">a link</a>
after parsing the post: <a href="/redirects/the_post"> a link</a>
and finally I need a redirect from /redirects/the_post to http:external.com/page1.htm
Because I have no experience with the wp_redirect function and I don't know if I need my own DB tables to solve the problem, I would really appreciate any kind of help.
Does your guy want to see what outbound links people are clicking?
You mean some kind of tracking? Yes, I mean first goal is getting it to work. And he also wants tracking but this can be done later.
It's apparent that the content is being parsed by PHP to give you the internal redirection link. All you need to do is find (do a search through your WP directory for '/redirect/' in the code) that parsing code and use a PHP header("Location:/redirects/the_post"); statement to effect the redirection. Okay, actually, I'd first use a header("status:302") for a temporary redirection (or 301 for a permanent redirection).
Since this is NOT a mod_rewrite question, though, I'd recommend that this thread be sent to the PHP board.
Thread has been moved to the Wordpress forum. As far as I know, header('status: 302') only works when PHP is running in (fast)cgi mode, not when running as a module.
Instead, you could use
header('Location: [noparse]http://www.example.com/bla/bla/bla[/noparse]', 302);
Note that the Location header actually needs a FQDN as opposed to a relative path; although the latter also works it's incorrect.
Problem is solved. I have found a link cloaking plugin that I can modify according to my needs. And adding some basic tracking functionality should be a peace of cake.
Thanks a million for the quick responses on my thread. Your answers gave the the right direction.