[pmwiki-users] Redirect to URL (not existing Wiki Page) - possible?

Patrick R. Michaud pmichaud at pobox.com
Fri Jan 12 07:00:20 CST 2007


On Thu, Jan 11, 2007 at 11:39:31PM -0000, Crisp, Steve [UK] wrote:
>    Why do I want to do it?  Well I'm running a random banner ad (on an
>    OpenSource software project site) using 'RandomPage'.  This rotates
>    through a few banner graphics.  If someone clicks on one it goes to a Wiki
>    page which I want to redirect to the external ad page.  I want to go via
>    an intermediate Wiki page because I want to register a hit on my Wiki page
>    so I can look at my web logs to get a quick click count for each banner. 
>    I'm sure there are better ways to do this.

Just brainstorming a bit here -- perhaps something like the following
would work...?

First, create local/Site.Redirect.php as follows:

    <?php
      if (@$_GET['url']) {
        header('Location: ' . $_GET['url']);
        exit();
      }

Then, anytime you want to do a redirect, use the following target:

    [[Site.Redirect?url=http://www.example.com/]]
    [[Site.Redirect?url=http://www.pmwiki.org/]]
    [[Site.Redirect?url=http://www.amazon.com/]]

This will take a browser to the Site.Redirect page (which will
record the click in your server log), from there it will be immediately
redirected to the external url.

If you need to have separate local targets for each redirect, you
could create a Redirect group, by placing the above configuration
as local/Redirect.php, and then using links like:

    [[Redirect.Example?url=http://www.example.com/]]
    [[Redirect.PmWiki?url=http://www.pmwiki.org/]]
    [[Redirect.Amazon?url=http://www.amazon.com/]]

This would enable the log to show hits to different pages, instead
of always using Site.Redirect.

Lastly, one could do this in a secure manner (so that others can't
create arbitrary redirections via the ?url= query parameter) with 
something like the following in a local customization (e.g., 
local/config.php):

    <?php
      $RedirectUrl = array(
        'Redirect.Example' => 'http://www.example.com/',
        'Redirect.PmWiki' => 'http://www.pmwiki.org/',
        'Other.Amazon' => 'http://www.amazon.com/');

      $pagename = ResolvePageName($pagename);
      if (@$RedirectUrl[$pagename]) {
        header("Location: {$RedirectUrl[$pagename]}");
        exit();
      }

Then, anyone who ends up at Redirect.Example, Redirect.PmWiki,
or Other.Amazon is automatically taken to the associated url.  
The (small?) downside is that you have to keep the $RedirectUrl
array up-to-date in the config file, but such is the price of
security.  :-)

We could also come up with a mechanism to hold the external
redirects in a separate editable Site.Redirects page -- something like:

    ABC.Amazon    http://www.amazon.com/
    ABC.Example   http://www.example.com/
    XYZ.PmWiki    http://www.pmwiki.org/

This page could be protected against edits, and landing on any
of the named pages would automatically result in a redirect to
the external url.

Just some ideas...

Pm




More information about the pmwiki-users mailing list