Skip to content

Instantly share code, notes, and snippets.

@chucktrukk
Created December 14, 2011 16:05
Show Gist options
  • Save chucktrukk/1477177 to your computer and use it in GitHub Desktop.
Save chucktrukk/1477177 to your computer and use it in GitHub Desktop.
MODx evolution 404 snippet for 301 redirects
<?php
$redirects = array(
'www.domain.com/old-url-1' => 'www.domain.com/new-url-1',
'www.domain.com/old-url-2' => 'www.domain.com/new-url-2',
);
$host = $_SERVER['HTTP_HOST'];
$url_parts = explode('?', $_SERVER['REQUEST_URI']);
$url_to_lookup = $host . $url_parts[0];
$new_url = isset($redirects[$url_to_lookup]) ? $redirects[$url_to_lookup] : null;
if( $new_url !== null ) {
header ('HTTP/1.1 301 Moved Permanently');
header ('Location: http://' . $new_url);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment