Advertisement
amaenta

rewrite

Mar 27th, 2019
94
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.63 KB | None | 0 0
  1. if (preg_match('/\/(\d+)-(.*).html/i', $uri, $match)) {
  2.     try {
  3.         $code = (int)$match[1];
  4.  
  5.         if ($code < 1) throw new Exception("Bad ID");
  6.  
  7.         $setup = parse_ini_file('../is/app/etc/setup.ini');
  8.         $rdb = new PDO('mysql:host=' . $setup['db.host'] . ';dbname=' . $setup['db.dbname'] . ';charset=utf8', $setup['db.username'], $setup['db.password']);
  9.  
  10.         $sth = $rdb->prepare('SELECT url FROM items i INNER JOIN routes r ON (i.item_id = r.id) WHERE i.item_id = ? AND r.tag = ? AND r.ver = 1 LIMIT 1');
  11.         $sth->execute([$code, 'routeItem']);
  12.         $row = $sth->fetch(PDO::FETCH_ASSOC);
  13.  
  14.         if ($row['url'] != '') {
  15.             header("Location: " . $row['url'], true, 301);
  16.             exit;
  17.         }
  18.     } catch (Exception $e) {
  19.  
  20.     }
  21.     header("Location: /");
  22.     exit;
  23. }
  24.  
  25. if (preg_match('/\/(\d+)-(.*)/i', $uri, $match)) {
  26.     try {
  27.         $code = (int)$match[1];
  28.  
  29.         if ($code < 1) throw new Exception("Bad ID");
  30.  
  31.         $setup = parse_ini_file('../is/app/etc/setup.ini');
  32.         $rdb = new PDO('mysql:host=' . $setup['db.host'] . ';dbname=' . $setup['db.dbname'] . ';charset=utf8', $setup['db.username'], $setup['db.password']);
  33.  
  34.         $sth = $rdb->prepare('SELECT url FROM kategorie k LEFT JOIN routes r ON (k.nowa = r.id) WHERE k.stara = ? AND r.tag = ? AND r.ver = 1 LIMIT 1');
  35.         $sth->execute([$code, 'routeCat']);
  36.         $row = $sth->fetch(PDO::FETCH_ASSOC);
  37.  
  38.         if ($row['url'] != '') {
  39.             header("Location: " . $row['url'], true, 301);
  40.             exit;
  41.         }
  42.     } catch (Exception $e) {
  43.  
  44.     }
  45.     header("Location: /");
  46.     exit;
  47. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement