Skip to content

Instantly share code, notes, and snippets.

@cubehrends
Last active November 7, 2018 08:49
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 cubehrends/b526a9f1f1a4d6c70ac543e1de67b0f7 to your computer and use it in GitHub Desktop.
Save cubehrends/b526a9f1f1a4d6c70ac543e1de67b0f7 to your computer and use it in GitHub Desktop.
301 Moved Permanently vie PHP header
<?php
function redirectTo( $location ) {
header( 'HTTP/1.1 301 Moved Permanently' );
header( 'Location: ' . $location );
header( 'Connection: close' );
}
switch ( $_SERVER['REQUEST_URI'] ) {
case '/post/an-uri-on-old-domain':
redirectTo( 'https://new-domain.com/a-new-uri/' );
break;
case '/post/another-uri-on-old-domain':
redirectTo( 'https://new-domain.com/another-new-uri/' );
break;
...
default:
break;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment