• Resolved Chris

    (@chips)


    I have a multisite installation but have no need for the main site. What I would like is for any public url’s on the main site to be redirected (301) to another site completely. However, I need the main site admin to remain accessible. I have tried this in my main site themes functions file;

    function redirect_entire_site() {
    
    	if( strpos( $_SERVER['REQUEST_URI'], '/wp-admin' ) === false || strpos( $_SERVER['REQUEST_URI'], '/wp-login' ) === false ) {
    
    		wp_redirect( 'https://new-domain.com/my-page/', 301 );
    		exit;
    
    	}
    
    }
    
    add_action( 'init', 'redirect_entire_site' );

    However it redirects everything, regardless of the current URI.

Viewing 1 replies (of 1 total)
  • Thread Starter Chris

    (@chips)

    I’ve figured out a working solution. If anyone else has been trying to accomplish this then the following function may help;

    function redirect_entire_site() {
    
    	/* Redirect to where? */
    	$redirect_url = 'https://domain.com/your-new-page/';
    
    	$uri = $GLOBALS['pagenow'];
    
    	if( !is_admin() ) {
    		$redirect = true;
    	}
    
    	if( strpos( $uri, 'wp-login' ) !== false ) {
    		$redirect = false;
    	}
    
    	if( $redirect == true ) {
    		wp_redirect( $redirect_url, 301 );
    		exit;
    	}
    
    }
    
    add_action( 'init', 'redirect_entire_site' );
Viewing 1 replies (of 1 total)
  • The topic ‘Redirect Main Site’ is closed to new replies.