Please wait, Page is Loading...
 

Summary: How to manage page redirect/alias?
Version:pre-alpha
Status: proposition
Maintainer: Dfolio
Categories: PmWiki | PHP

Description

This recipe aims at providing a simple way to build multiple page redirection and/or alias. Thus this recipe allow to manage multiple page redirection and/or alias simply from a wiki page. It’s work as InterMap, ie. the admin user provide a list of redirection page (that is alias). For instance, consider the following page redirection list:

  • PageA:PageB
  • GroupA.PageAA: GroupB.PageB
  • PageC: PageB

Here only PageB must exist, all other is redirect to PageB. Notice that if no group is specified the current is used.

Use

Here the proposed PHP code:

function CheckRedirect($pagename){
  global $RedirectFiles,$RedirectStatus,$EnableRedirectQuiet;
  SDVA($RedirectFiles,array('$Group.Redirect','$SiteGroup.Redirect'));
  SDV($RedirectStatus,301);
  foreach((array)$RedirectFiles as $f) {
    $f = FmtPageName($f, $pagename);
    if (($v = @file($f)))
      $v = preg_replace('/^\\s*(?>\\w[-\\w]*)(?!:)/m', '$0:', implode('', $v));
    else if (PageExists($f)) {
      $p = ReadPage($f, READPAGE_CURRENT);
      $v = $p['text'];
    } else continue;
    if (!preg_match_all("/^[\*#:]?\\s*(\\S*):[^\\S\n]*(\\S*)/m",
                        $v, $match, PREG_SET_ORDER)) continue;
    foreach($match as $m) {
      $from= FmtPageName($m[1],$pagename);
      $to= MakePageName($pagename, $m[2]); $anchor ="";
      if (preg_match('/^([^#]+)(#[A-Za-z][-\\w]*)$/', $to, $match))
      { $to = $match[1]; $anchor = $match[2]; }
      if ((PageExists($to))&&($from!==$to)&&
          (($from===$pagename)||MatchPageNames($pagename,$from))){
        StopWatch("CheckRedirect: [$pagename match $from] --> $to");
        if (preg_match('/^30[1237]$/', $RedirectStatus)) header("HTTP/1.1 {$RedirectStatus}");
        if ( IsEnabled($EnableRedirectQuiet, 0) && ($RedirectStatus == '301') ) Redirect($to, "{\$PageUrl}");
        else Redirect($to, "{\$PageUrl}?from=$pagename$anchor");
      }
    }
  }
}

Place the above code in to your {$FarmD}/local/config.php, and then add:

CheckRedirect($pagename);

Next the admin user have to create $SiteGroup.Redirect or $Group.Redirect pages and add the redirection list.



Commentaire

Remark, suggestion post a comment:

Ta bite06 septembre 2012, 22:08

Tu as une petite bite, prends du viagra!!!

Ta bite06 septembre 2012, 22:09

Tu as une petite bite, prends du viagra!!!

Ta bite06 septembre 2012, 22:14

Tu as une petite bite, prends du viagra!!!

Signer en tant qu'auteur 
Website 

Veuillez indiquer un nom d'auteur, et entrer la valeur du code (limite le spam...). Merci.


  • Add This
  • Add
  • Get
  • Google

default