SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    301 redirect on the fly...

    Hi all,

    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.

    example:

    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.

    thanks

  2. #2
    SitePoint Wizard rguy84's Avatar
    Join Date
    Sep 2005
    Location
    Durham, NC
    Posts
    1,659
    Mentioned
    5 Post(s)
    Tagged
    0 Thread(s)
    Does your guy want to see what outbound links people are clicking?
    Ryan B | My Blog | Twitter

  3. #3
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.

  4. #4
    Certified Ethical Hacker silver trophybronze trophy dklynn's Avatar
    Join Date
    Feb 2002
    Location
    Auckland
    Posts
    14,653
    Mentioned
    19 Post(s)
    Tagged
    3 Thread(s)
    aszy,

    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.

    Regards,

    DK
    David K. Lynn - Data Koncepts is a long-time WebHostingBuzz (US/UK)
    Client and (unpaid) WHB Ambassador
    mod_rewrite Tutorial Article (setup, config, test & write
    mod_rewrite regex w/sample code) and Code Generator

  5. #5
    Utopia, Inc. silver trophy
    ScallioXTX's Avatar
    Join Date
    Aug 2008
    Location
    The Netherlands
    Posts
    9,081
    Mentioned
    153 Post(s)
    Tagged
    2 Thread(s)
    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: http://www.example.com/bla/bla/bla', 302);
    Note that the Location header actually needs a FQDN as opposed to a relative path; although the latter also works it's incorrect.
    Rémon - Hosting Advisor

    SitePoint forums will switch to Discourse soon! Make sure you're ready for it!

    Minimal Bookmarks Tree
    My Google Chrome extension: browsing bookmarks made easy

  6. #6
    SitePoint Member
    Join Date
    Jan 2012
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    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.


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •