Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WordPress Multisite Network Doesn't Work #69

Open
bratvanov opened this issue Sep 26, 2019 · 2 comments
Open

WordPress Multisite Network Doesn't Work #69

bratvanov opened this issue Sep 26, 2019 · 2 comments

Comments

@bratvanov
Copy link

Using the helper to install WordPress in Google App Engine and then creating a Multisite Network using sub-directories.

This has a couple of major issues in wp-admin for any site that's not the main network site:

  1. The network admin dashboard at https://example.appspot.com/wp-admin/network/ loads the front-end theme's index.php.

  2. The admin dashboard for any network site has a redirect loop i.e https://example.appspot.com/new-network-site-name/wp-admin/

As far as I can tell, this has something to do with the get_real_file_to_load() function in gae-app.php not supporting WordPress multisite?

@jimmycann
Copy link

For anyone else running into this problem, @Euene suggestion that get_real_file_to_load() is not compatible with WP multisite is correct. I was able to fix it however by making some small modifications to the gae-app.php file.

function get_real_file_to_load($full_request_uri)
{
    $request_uri = @parse_url($full_request_uri)['path'];

    // Redirect /wp-admin to /wp-admin/ (adds a trailing slash)
    if ($request_uri === '/wp-admin') {
        header('Location: /wp-admin/');
        exit;
    }

    // Redirect /subfolder/wp-admin to /subfolder/wp-admin/ (adds a trailing slash)
    if ($request_uri === '/subfolder/wp-admin') {
        header('Location: /subfolder/wp-admin/');
        exit;
    }

    // Serve up "index.php" when /wp-admin/ is requested
    if ($request_uri === '/wp-admin/') {
        return '/wp-admin/index.php';
    }

    // Fix for the network page redirecting to main page
    if ($request_uri === '/wp-admin/network/') {
        return '/wp-admin/network.php';
    }

    // Serve up "index.php" when /subfolder/wp-admin/ is requested
    if ($request_uri === '/subfolder/wp-admin/') {
        return '/wp-admin/index.php';
    }

    // Fix for login redirect heading back to the subfolder page 
    if ($request_uri === '/subfolder/wp-login') {
        return '/wp-login.php';
    }

    // Fix for subfolder content paths
    if (strpos($request_uri, '/subfolder/wp-') !== false) {
        return str_replace("/subfolder/wp-", "/wp-", $request_uri);
    }

    // Load the file requested if it exists
    if (is_file(__DIR__ . $request_uri)) {
        return $request_uri;
    }

    // Send everything else through index.php
    return '/index.php';
}

// fixes b/111391534
$_SERVER['HTTPS'] = $_SERVER['HTTP_X_APPENGINE_HTTPS'];

// Loads the expected WordPress framework file
// (e.g index.php, wp-admin/* or wp-login.php)
$file = get_real_file_to_load($_SERVER['REQUEST_URI']);

// Set the environment variables to reflect the script we're loading
// (in order to trick WordPress)
$_SERVER['DOCUMENT_URI']    = $_ENV['DOCUMENT_URI']    = $file;
$_SERVER['PHP_SELF']        = $_ENV['PHP_SELF']        = $file;
$_SERVER['SCRIPT_NAME']     = $_ENV['SCRIPT_NAME']     = $file;
$_SERVER['SCRIPT_FILENAME'] = $_ENV['SCRIPT_FILENAME'] = __DIR__ . $file;

require __DIR__ . $file;

This could probably be shorter and more concise, but it should demonstrate how to resolve the issue. Note that this is only for the "subfolder" multisite method.

Will recap here for potentially easier googling (I had to hunt around for a while with a lot of dead ends)

  • Fixes multisite subfolder wp-admin page 302 redirect loop
  • Fixes content loading once inside the admin multisite subfolder dashboard
  • Fixes wp-login serving the multisite "Page not found" page instead of the login page
  • Fixes the multisite network page

@bshaffer
Copy link
Contributor

This is great, thank you for finding this! Perhaps it'd be better if we included a gae-app-multisite.php with your above configuration. Or, if there's an environment variable or wp configuration we can parse to determine if the app is multisite, we can wrap your additions in a conditional for when that configuration is true.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants