How can I reach ms_site_not_found action? (6 posts)

  1. katazina
    Posted 1 year ago #


    when a subdomain is not found, then wp redirects to the wp-signup.php.
    In that case, I want to load a 404 page instead, without any redirecting, because the redirecting can cause negative seo.

    I found the ms_site_not_found action, and I tried to hook to it, but nothing happened. The hooked function never fires.

    For example in the mu-plugins directory, I wrote that:

    add_action('ms_site_not_found', 'sitenotfound');
    function sitenotfound()

    and the die('111'); line never runs. Nothing runs in this function.

    Can anyone help me, why this action not working?

    If i write a die() line anywhere else in this file, that working, but the function not.

  2. We already have that covered :) Add this to your wp-config:

    define( 'NOBLOGREDIRECT', 'http://www.example.com/page--to-go-to' );

  3. katazina
    Posted 1 year ago #

    That's not good either, that still redirecting, i tried.
    First the core code does a redirect with 302, then got the 404 (my page status).

    The ms_site_not_found action is before the redirecting code, that's why I wanted to use it.
    I had to hard coded a require_once(...) and exit(), because I didn't found a proper way to do that.

    How can I use the ms_site_not_found action, or if I used it properly, than why it's not working?

  4. schlimpf
    Posted 1 year ago #


    I am also interested in this topic.
    NOBLOGREDIRECT only works on subdomain installs, not for subdirectories.


  5. katazina - You are incorrect that it will cause a problem to SEO. The 302 redirect is the one that SAVES your SEO :) You're fine. Don't worry about it.

    schlimpf - That's because a 404 on a subFOLDER site is just a 404 on the main site :)

    So if you install at example.com and go to example.com/fakesite that's the same as going to example.com/fakepage

    There's no need to use the define.

  6. scm6079
    Posted 10 months ago #

    For the next person who may end up here trying to figure out why the ms_site_not_found action isn't firing for them -- the docs don't mention you must bind it in sunrise.php, since none of the plugins (including must-use plugins) have been initialized by the time this action is fired.

    In your wp_config.php, add the define:

    define( 'SUNRISE', 'on' );

    In your sunrise.php file, include:

    function your_function_name($current_site, $domain, $path) {
       die('Site ' . $domain . ' not found.');
    add_action('ms_site_not_found', 'your_function_name', 10, 3);

    Make sure to place sunrise.php in your wp-content folder.

Topic Closed

This topic has been closed to new replies.

About this Topic