-
-
Save netconstructor/2567157 to your computer and use it in GitHub Desktop.
PHP redirects
This file contains hidden or 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 | |
add_action ('wp_head', 'rkv_new_redirects', 1); // create redirects | |
function rkv_new_redirects() { | |
$newurl = 'http://mynewurl.com'; | |
$slug = basename(get_permalink()); | |
$cat = get_query_var('cat'); | |
$cat_s = get_category ($cat); | |
$c_slug = $cat_s->slug; | |
// set up | |
if (is_home() || is_front_page() ) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.$newurl.'/'); | |
} | |
elseif (is_category() ) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.$newurl.'/category/'.$c_slug.'/'); | |
} | |
elseif (is_page() ) { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.$newurl.'/'.$slug.'/'); | |
} | |
elseif (is_singular('post') ) { // may take some tweaking depending on site URL structure | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.$newurl.'/'.$slug.'/'); | |
} | |
else { | |
header('HTTP/1.1 301 Moved Permanently'); | |
header('Location: '.$newurl.'/'); | |
} | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment