Skip to content

Instantly share code, notes, and snippets.

@timplumb
Created February 25, 2019 17:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save timplumb/62cac1fcb1a4ecffa36d80baefd4a8a6 to your computer and use it in GitHub Desktop.
Save timplumb/62cac1fcb1a4ecffa36d80baefd4a8a6 to your computer and use it in GitHub Desktop.
Pulse CMS Redirection plug-in
{{redirection}}
<?php
/*
Permanent redirection (301) for old page links
*/
$redirectsdatafile = "content/blocks/sb_redirection.txt"; // the super block that holds the redirection data
if (file_exists($redirectsdatafile)){
$urlparts = str_replace($path."/","",$_SERVER['REQUEST_URI']);
$urlparts = explode("/",$urlparts);
$redirectcode = $urlparts[0];
$newdata = "";
$redirectsdata = file_get_contents($redirectsdatafile);
$data = explode("\n",$redirectsdata);
$len = count($data);
$i = 0;
foreach($data as $row){
$rowdata = explode(",",$row);
$hits = $rowdata[2];
if($rowdata[0] === $redirectcode){
$redirectto = $rowdata[1];
$hits = $rowdata[2] + 1;
}
$newdata .= $rowdata[0] . "," . $rowdata[1] . "," . $hits;
if ($i < ($len - 1)){ $newdata .= "\n"; }
$i++;
}
//redirect
if ($redirectto){
//write the data to the file
//$handle = fopen($redirectsdatafile, 'w') or die('Cannot open file: '.$redirectsdatafile);
//fwrite($handle, $newdata);
//fclose($handle);
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$redirectto);
exit;
}
}
?>
our-meat,/shop/our-meat,1
products,/shop,1
where-to-buy,/shop/where-to-buy,1
news,/,1
@timplumb
Copy link
Author

Copy link

ghost commented Feb 27, 2019

Great solution @timplumb

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment