Moved the wordpress blog from my_site.net to my_site.net/blog/ in the root of the site is now landing page need redirect to the desired blog article at a new address. Those. if a person came to the site by the link my_site.net/category/projects / ... then he should be redirected with the addition of the directory "blog" my_site.net/blog/category/projects / ...
1 answer
In the function.php theme add:
add_action( 'template_redirect', function() { $search = '/category/projects/'; $replace = '/blog/category/projects/'; $uri = $_SERVER['REQUEST_URI']; $path = parse_url($uri, PHP_URL_PATH); $pos = strpos($path, $search); if ($pos !== false) { $path = str_replace($search, $replace, $path); wp_redirect( $path , 301 ); exit; } } );
|