6

If we try to access a non-existant Multisite site, e.g., http://site1.example.com or http://example.com/site1/, we are redirected to http://example.com/wp-signup.php?new=site1.

How to block this and redirect the browser to another page?

3 Answers 3

18

[Update]

An alternative (maybe better) is to use the following constant in wp-config.php:

define( 'NOBLOGREDIRECT', 'http://example.com' );

At the very beginning of wp-signup.php file there is this code:

function do_signup_header() {
    do_action( 'signup_header' );
}
add_action( 'wp_head', 'do_signup_header' );

So, it's just a matter of adding the signup_header action hook to break any further execution and redirect the browser to other URL.

Here, wrapped as a Must Use Plugin:

<?php
/*
    Plugin Name: Multisite - Prevent Sign-up Page
    Plugin Url: http://wordpress.stackexchange.com/q/85529/12615
    Version: 1.0
    Author: Rodolfo Buaiz
*/

add_action( 'signup_header', 'rbz_prevent_multisite_signup' );

function rbz_prevent_multisite_signup() 
{
    wp_redirect( site_url() );
    die();
}
6
  • 1
    @kaiser, always disliked this behavior in closed networks ;)
    – brasofilo
    Feb 13, 2013 at 12:18
  • hey, unser @kaiser, there's a better alternative, IMO. Updated the A with it. Also published a related one.
    – brasofilo
    May 3, 2013 at 1:18
  • I just wanted to state that I dislike the core behavior. In the meanwhile I found the regarding DropIns, when I talked about them. +1 on both answers.
    – kaiser
    May 3, 2013 at 10:12
  • 1
    Was messing around a lot with function to prevent redirects and .htaccess to recognize */wp-signup.php to redirect to the network home page. The define( 'NOBLOGREDIRECT', %URL% ); finally solved it! +1 (noteworthy: result not necessarily visible on localhost with custom URL redirect using Windows hosts file)
    – rkeet
    Oct 20, 2014 at 13:42
  • 1
    This is incorrect - the hook used should be before_signup_header, not signup_header. otherwise you receive 'Headers already sent' errors.
    – Mark
    Jul 30, 2017 at 8:55
1

I found a solution in this article

I had the wrong SUBDOMAIN_INSTALL setting value in my config file.

1
  • A link-only answer will become invalid with a dead link. Would you please edit and elaborate your answer in brief and then provide the link for additional information? Nov 30, 2014 at 5:03
1

Simply add the following to wp-content/mu-plugins/disable-signups.php:

<?php
remove_action( 'wp_head', 'do_signup_header' );

The signup page will now say:

Registration has been disabled.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.