Skip to content

Instantly share code, notes, and snippets.

@dendeffe
Created November 14, 2017 08:37
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 dendeffe/1a3903caf671b71617ca0675cab6d6f4 to your computer and use it in GitHub Desktop.
Save dendeffe/1a3903caf671b71617ca0675cab6d6f4 to your computer and use it in GitHub Desktop.
<?php
$file = fopen("dicar.csv","r");
while (($data = fgetcsv($file)) !== FALSE) {
//echo "<pre>";print_r($data);
$split_old_url = explode("?", $data[0]);
$querystring = $split_old_url[1];
$url = $split_old_url[0];
$url = explode('/', $url);
$final_url = "";
$counter = 0;
foreach($url as $url_part) {
if($counter > 0) {
$final_url .= $url_part . "/";
}
$counter++;
}
$final_url = substr($final_url, 0, -1);
if(strpos($querystring, "ID") !== false || strpos($querystring, "act") !== false || strpos($querystring, "Category") !== false || strpos($querystring, "nav=prof") !== false) {
echo "RewriteCond %{QUERY_STRING} " . $querystring . "<br>";
echo "RewriteRule ^" . $final_url . "(.*)$ " . $data[1] . "? [R=301,L]<br>";
} else {
echo "RewriteRule ^" . $final_url . "(.*)$ " . $data[1] . "? [R=301,L]<br>";
}
}
fclose($file);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment