Snippet: Redirect Main Site To Sub-Site

Add following snippet to “functions.php”

Snippet

add_action('parse_request', 'wpds_redirect_to_sub_site');
function wpds_redirect_to_sub_site(){
    global $wp;

    if('http://www.example.com' === $wp->request){

        $url = 'http://www.example.com/subsite';
        wp_redirect($url, 301);
        exit;
    }
}

Result

All the requests to ‘www.example.com’ will be redirected to ‘www.example.com/subsite’.

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>