Created
February 25, 2019 17:04
-
-
Save timplumb/62cac1fcb1a4ecffa36d80baefd4a8a6 to your computer and use it in GitHub Desktop.
Pulse CMS Redirection plug-in
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{{redirection}} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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; | |
} | |
} | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
our-meat,/shop/our-meat,1 | |
products,/shop,1 | |
where-to-buy,/shop/where-to-buy,1 | |
news,/,1 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
For set up notes see https://forum.pulsecms.com/t/redirect-old-php-pages/1353