themosis / framework

The Themosis framework core.
https://framework.themosis.com/
GNU General Public License v2.0
672 stars 121 forks source link

Multisite wp-admin subdirectory install redirect loop #496

Closed mihazs closed 6 years ago

mihazs commented 6 years ago

Hello, first of all, congratulations for this framework, it have changed my way of work with wordpress.

I'm trying to working with multisite and themosis in a shared hosting, and because of that, i'm not able to use subdomain based multisite, so, i use subdirectory.

The network panel and the main site panel works fine, but if i try to create a new site, i'm not able to acess his panel. The hosting doesn't allow to change the folder name where i put the public site files, so, i have maked a rule in .htaccess to supress the "htdocs" from the urls.

I have followed all the steps of the documentation, and no success.

So, there is my .htaccess file:

`Options -Indexes

RewriteEngine On RewriteRule ^moodle/.*$ - [PT] RewriteRule ^(.*)$ htdocs/$1 [L] # redirect to https www RewriteCond %{HTTPS} off RewriteCond %{HTTP_HOST} ^(?:www\.)(domain\.com)$ [NC] RewriteRule ^ https://www.%1%{REQUEST_URI} [R=301,L] # redirect to http subdomain RewriteCond %{HTTPS} on RewriteCond %{HTTP_HOST} ^((?!www).+\.domain\.com)$ [NC] RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L] RewriteBase / RewriteRule ^index\.php$ - [L] # add a trailing slash to /wp-admin RewriteRule ^([_0-9a-zA-Z-]+/)?wp-admin$ $1wp-admin/ [R=301,L] RewriteCond %{REQUEST_FILENAME} -f [OR] RewriteCond %{REQUEST_FILENAME} -d RewriteRule ^ - [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(wp-(content|admin|includes).*) htdocs/cms/$2 [L] RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ htdocs/cms/$2 [L] RewriteRule . index.php [L] SecFilterEngine Off SecFilterScanPOST Off

`

And there is my local.php file:

`<?php

/----------------------------------------------------/ // Local config /----------------------------------------------------/ // Database define('DB_NAME', getenv('DB_NAME')); define('DB_USER', getenv('DB_USER')); define('DB_PASSWORD', getenv('DB_PASSWORD')); define('DB_HOST', getenv('DB_HOST') ? getenv('DB_HOST') : 'localhost');

// WordPress URLs define('WP_HOME', getenv('WP_HOME')); define('WP_SITEURL', getenv('WP_SITEURL'));

// Jetpack define('JETPACK_DEV_DEBUG', false);

// Encoding define('THEMOSIS_CHARSET', 'UTF-8');

// Development define('SAVEQUERIES', true); define( 'WP_DEBUG_DISPLAY', false ); define( "WP_DEBUG", true ); define( "WP_DEBUG_LOG", true ); // Themosis framework define('THEMOSIS_ERROR', false); define('BS', true);

define('WP_MEMORY_LIMIT', '256MB'); define('DISABLE_WP_CRON', true);

define('ADMIN_COOKIE_PATH', '/'); //define('COOKIE_DOMAIN', ''); define('COOKIEPATH', ''); define('SITECOOKIEPATH', '');

define( 'WP_ALLOW_MULTISITE', true ); define('MULTISITE', true); define('SUBDOMAIN_INSTALL', false); // Set to false if you selected the "Sub-directories" installation. define('DOMAIN_CURRENT_SITE', 'cfnplages.com.br'); // Main domain. Same as defined in your .env.local file without the http protocol. define('PATH_CURRENT_SITE', '/'); define('SITE_ID_CURRENT_SITE', 1); define('BLOG_ID_CURRENT_SITE', 1); ` I already changed the wp_options table, and didn't work. Thanks.

jlambe commented 6 years ago

What is the kind of URL you're expecting and what is the URL that you get instead?

mihazs commented 6 years ago

I'm expecting something like mysite.com/sitename/wp-admin/ and i'm getting. Before, i was getting something like mysite.com/sitename/cms/wp-admin/, and to fix that i put this file in the muplugins folder:

fixurl.php

<?php

/*
Plugin Name: Network Admin URL Fix
Description: Fix the URL to the network admin pages when using a custom WordPress path.
Author: Julien Lambé
Version: 1.0
Author URI: http://www.themosis.com/
Date: 4/06/17
Time: 14:52
*/

/**
 * Parse and fix network admin url.
 *
 * @param string $url The full default URL to parse.
 * @param string $delimiter The delimiter string to use in order to fragment URL.
 *
 * @return string
 */
function themosis_admin_url($url, $delimiter = 'wp-admin')
{
    /*
     * If there is already a "cms" fragment in the URI,
     * just return the URL.
     */
    if (strrpos($url, 'cms') !== false) {
        return $url;
    }

    /*
     * The network admin URL is missing the "cms" fragment.
     * Let's add it.
     */
    $fragments = explode($delimiter, $url);

    /*
     * Insert in the middle the cms fragment appended with the wp-admin delimiter.
     */
    array_splice($fragments, 1, 0, "cms/{$delimiter}");

    /*
     * Build the URL by reducing (concatenating) all fragments.
     * This appends each fragment to the previous one.
     */
    $url = array_reduce($fragments, function ($carry, $item) {
        return $carry.=$item;
    });

    return $url;
}

/*
 * Filter the network URL.
 */
add_filter('network_admin_url', function ($url) {
    return themosis_admin_url($url);
});

/*
 * Filter the default admin URL.
 */
add_filter('admin_url', function ($url, $path, $blog_id) {
    if($blog_id == 1){
    return themosis_admin_url($url);
    } else return $url;
}, 10, 3);

/*
 * Filter the includes URL.
 */
add_filter('includes_url', function ($url) {
    return themosis_admin_url($url, WPINC);
});

doesn't matter the url, i just wanna make the panel of the subsites work with subdirectories.

mihazs commented 6 years ago

Have any idea?

jlambe commented 6 years ago

I suppose that the URL should indeed be mysite.com/sitename/cms/wp-admin as WordPress administration is in the cms folder. You should not remove the cms uri.

Regarding the file you have found, it is fixing URLs regarding a subdomain installation. But all required filters are defined in this file so you should experiment with it in order to make your installation work. Due to the project structure, you have to keep the cms URI though. Trying to remove it is just not an option.

mihazs commented 6 years ago

Ok, i've changed to get the mysite.com/sitename/cms/wp-admin/ in the subsites. The main site, and the network panel works well in mysite.com/cms/wp-admin/ but the others sites give me the white screen of death (the wp famous). I've already set the debug constants to true and i'm getting no info about it. The redirecting loop has stopped. I've changed now the theme of the new site i've created to the theme that i'm using, i do this directly in wp_5_options, and now i'm getting this error:

image

i'm very lost.

jlambe commented 6 years ago

The error you get is because you haven't attached your role function/callback to a WordPress hook. So your code is running too early and the $role variable is not yet defined as an object -> error.

You should call your function with the init hook.

mihazs commented 6 years ago

Ok, i've done that, and this error was gone, now, i'm getting a 404 page when i try to access the wp-admin of the subsite, only is subsites.