Skip to content

Instantly share code, notes, and snippets.

@saschaludwig
Last active February 27, 2018 13:16
Show Gist options
  • Save saschaludwig/63f5f0ccf8c94211cb69a3143b6eac72 to your computer and use it in GitHub Desktop.
Save saschaludwig/63f5f0ccf8c94211cb69a3143b6eac72 to your computer and use it in GitHub Desktop.
mediawiki to dokuwiki url redirector
<?php
// mediawiki to dokuwiki url redirector
// use .htaccess to rewrite all requests to this file:
// RewriteEngine on
// RewriteCond %{REQUEST_FILENAME} !-f
// RewriteCond %{REQUEST_FILENAME} !-d
// RewriteRule ^(.*)$ /wiki/index.php [NC,L,QSA]
$prefix = '/wiki';
// static replaces
$statics = [
'/index.php/Main_Page' => '/doku/start',
'/index.php/SIP/IAX_Configuration_hints' => '/doku/sip_configuration_hints'
];
function doRedirect($redir) {
$url = "https://eventphone.de".$redir;
header("HTTP/1.1 301 Moved Permanently");
header("Location: ".$url);
header("Connection: close");
die();
}
$uri = $_SERVER['REQUEST_URI'];
// remove prefix from URI
$req = preg_replace('/^' . preg_quote($prefix, '/') . '/', '', $uri);
// process static replaces first
$redir = strtr($req, $statics);
if ( $redir != $req ) { doRedirect($redir); }
// mediawiki -> dokuwiki url
$redir = strtolower($req);
$redir = str_replace("/index.php/", "", $redir);
$redir = str_replace("/", "_", $redir);
$redir = "/doku/".$redir;
doRedirect($redir);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment