[Support request] WordPress Multisite redirects subpages to homepage

Home Forums Multisite WordPress Multisite redirects subpages to homepage

Viewing 9 posts - 1 through 9 (of 9 total)
  • Author
    Posts
  • #288904
    maxime
    Participant

    Hi,
    Summary of the problem: I have a new wordpress multisite set up as subdirectories (same base URL with languages subdirectories, like domain.com/en-gb/ for example), it’s working fine in itself apart from this one very annoying issue: Everytime I am trying to access a subpage of the main domain (like domain.com/page/ or domain.com/wp-config for example), it redirects to the homepage of this domain (domain.com).

    Observation 1: This weirdly only happens the first time you try to load a subpage of the main domain on a tab. Like for example, you are on facebook, see an ad, click on the link domain.com/subpage, or say you open a blank tab and type domain.com/wp-admin, you get redirected to domain.com. BUT THEN, if now from this tab you try to go to the subpage (any subpage), it works fine. That’s only happening the first time you load the domain on the page.

    Observation 2: I think the problem started when I enabled SSL with the plugin Really Simple SSL. I tried deleting its part of the .htaccess file, but that didn’t solve anything. I don’t know if it adds anything else than the lines in .htaccess (like some redirection in the database maybe?). I think I enabled it on the main site initially (and not on the network dashboard), this is why I’m wondering if it’s involved somehow.

    Observation 3: This problem doesn’t seem to affect the subdirectories. For example, if I go to domain.com/en-gb/page, that works as it should, even on a new blank tab. It seems that only the main domain is concerned.

    Permalinks are set to Custom : /%postname%/

    Server Info: Apache Hosting company: OVH PHP Version: 7.3.6 MySQL vesion: 5.6.43

    Here is the .htaccess (with Really Simple SSH part already deleted) :

    # BEGIN WordPress
    <IfModule mod_rewrite.c>
    RewriteEngine On
    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).*) $2 [L]
    RewriteRule ^([_0-9a-zA-Z-]+/)?(.*\.php)$ $2 [L]
    RewriteRule . index.php [L]
    </IfModule>
    # END WordPress
    # BEGIN ShortPixelWebp
    # END ShortPixelWebp

    I suppose you know, but this is what I deleted from Really Simple SSL :

    # BEGIN rlrssslReallySimpleSSL rsssl_version[3.2.2]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    </IfModule>
    # END rlrssslReallySimpleSSL

    And here is the wp-config.php (without logins) :

    <?php
    /**
     * The base configuration for WordPress
     *
     * The wp-config.php creation script uses this file during the
     * installation. You don't have to use the web site, you can
     * copy this file to "wp-config.php" and fill in the values.
     *
     * This file contains the following configurations:
     *
     * * MySQL settings
     * * Secret keys
     * * Database table prefix
     * * ABSPATH
     *
     * @link https://codex.wordpress.org/Editing_wp-config.php
     *
     * @package WordPress
     */
    
    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'XXXXXXXXXXXX');
    
    /** MySQL database username */
    define('DB_USER', 'XXXXXXXXXXXX');
    
    /** MySQL database password */
    define('DB_PASSWORD', 'XXXXXXXXXXXX');
    
    /** MySQL hostname */
    define('DB_HOST', 'XXXXXXXXXXXX');
    
    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8');
    
    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');
    
    /**#@+
     * Authentication Unique Keys and Salts.
     *
     * Change these to different unique phrases!
     * You can generate these using the {@link https://api.wordpress.org/secret-key/1.1/salt/ WordPress.org secret-key service}
     * You can change these at any point in time to invalidate all existing cookies. This will force all users to have to log in again.
     *
     * @since 2.6.0
     */
    define('AUTH_KEY',         'XXXXXXXXXXXX');
    define('SECURE_AUTH_KEY',  'XXXXXXXXXXXX');
    define('LOGGED_IN_KEY',    'XXXXXXXXXXXX');
    define('NONCE_KEY',        'XXXXXXXXXXXX');
    define('AUTH_SALT',        'XXXXXXXXXXXX');
    define('SECURE_AUTH_SALT', 'XXXXXXXXXXXX');
    define('LOGGED_IN_SALT',   'XXXXXXXXXXXX');
    define('NONCE_SALT',       'XXXXXXXXXXXX');
    
    /**#@-*/
    
    /**
     * WordPress Database Table prefix.
     *
     * You can have multiple installations in one database if you give each
     * a unique prefix. Only numbers, letters, and underscores please!
     */
    $table_prefix  = 'mod155_';
    
    /**
     * For developers: WordPress debugging mode.
     *
     * Change this to true to enable the display of notices during development.
     * It is strongly recommended that plugin and theme developers use WP_DEBUG
     * in their development environments.
     *
     * For information on other constants that can be used for debugging,
     * visit the Codex.
     *
     * @link https://codex.wordpress.org/Debugging_in_WordPress
     */
    define('WP_DEBUG', false);
    
    /* Multisite */
    define('MULTISITE', true);
    define('SUBDOMAIN_INSTALL', false);
    define('DOMAIN_CURRENT_SITE', 'www.XXXXXXXXXXXX.co');
    define('PATH_CURRENT_SITE', '/');
    define('SITE_ID_CURRENT_SITE', 1);
    define('BLOG_ID_CURRENT_SITE', 1);
    define('NOBLOGREDIRECT', 'https://www.XXXXXXXXXXXX.co' );
    
    define('ADMIN_COOKIE_PATH', '/');
    define('COOKIE_DOMAIN', '');
    define('COOKIEPATH', '');
    define('SITECOOKIEPATH', '');
    
    /* That's all, stop editing! Happy blogging. */
    
    /** Absolute path to the WordPress directory. */
    if ( !defined('ABSPATH') )
        define('ABSPATH', dirname(__FILE__) . '/');
    
    /* Fixes "Add media button not working", see http://www.carnfieldwebdesign.co.uk/blog/wordpress-fix-add-media-button-not-working/ */
    define('CONCATENATE_SCRIPTS', false );
    
    /** Sets up WordPress vars and included files. */
    require_once(ABSPATH . 'wp-settings.php');

    That is really annoying and is obviously lowering the conversion rate of the main website (because all the trafic is redirected to homepage no matter what)

    Could you help me solve this? I have all access across the whole website / database, so I can try anything.

    Thanks in advance,
    Maxime

    #288909
    Mark
    Keymaster

    Hi Maxime,

    it seems that part of the request goes missing when you try to access domain.com/page. Have you enabled a different redirect option in the plugin settings, for example the 301 WordPress redirect after removing the .htaccess rules from the .htaccess file?

    One thing you could try is to slightly alter the .htaccess redirect inserted by Really Simple SSL, replacing this line:

    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]

    with:

    RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

    There is a slight difference in the way $1 and {REQUEST_URI} handle redirects which seems to affect multisites. Can you try if that resolves your issue?

    Mark

    #288910
    maxime
    Participant

    Hey Mark, thanks for your quick answer.

    So, I tried disabling 301 WordPress redirect, which didn’t seemed to have any effect, I re-enabled it.
    I then replaced the line in .htaccess, didn’t worked either…

    Are we clear that on a wordpress multisite the .htaccess file is still at the same place as usual at the root of the folder in FTP?

    #288912
    maxime
    Participant

    In the Google Chrome console, it appears that when I try to load a subpage, there is first a 301 error, and then a 302.

    Also, if I set permalinks to plain, and try to access the page via its page ID, it works normally.

    #288916
    Mark
    Keymaster

    Yes, that’s the correct .htaccess file. It could be possible that this is caused by something else than Really Simple SSL, especially since setting the permalinks to plain does work. Does the issue persists with all redirect options disabled? You could also try to press the ‘Deactivate and keep SSL’ button in the settings tab. That will have the same effect as disabling all redirects. If the issue persists after disabling all redirects, it’s possible that a security plugin is causing this issue. Some security/bot blocking plugins have options to redirect requests to the homepage.

    Really Simple SSL only adds a 301 redirect, if the 302 redirect is redirecting to the homepage it’s definitely not caused by Really Simple SSL. Check your security plugins and hosting/CDN redirect rules if you use any.

    Mark

    #288920
    maxime
    Participant

    Actually, I didn’t realized that when I tested with plain permalinks, I did differently: I copy pasted the url (I was typing it while testing before).

    I get it and I am now fully able to replicate the error : It only happens when “www.” is missing.

    If I type or paste the url with (thus being automatically properly set to https://www.domain.com./page), it goes right to the good page. If I type it without “www.”, then there is the error and it goes to homepage.
    How could I make the urls without “www.” be redirected to the correct url with “www.” ?

    • This reply was modified 1 month, 1 week ago by maxime.
    #288928
    Mark
    Keymaster

    You can redirect non-www requests to www by adding the following to your .htaccess file:

    RewriteEngine On
    
    RewriteCond %{HTTP_HOST} !^www\.
    
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [R=301,L]

    These rules should be added outside (above) the # WordPress and # Really Simple SSL blocks. For more information see https://really-simple-ssl.com/knowledge-base/avoid-landing-page-redirects/.

    #288931
    maxime
    Participant

    Solved it ! 🙂
    So now there is that :

    RewriteEngine On
    RewriteCond %{HTTPS} off
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [L,R=301]
    RewriteCond %{HTTP_HOST} !^www\. [NC]
    RewriteRule ^(.*)$ https://www.%{HTTP_HOST}/$1 [L,R=301]

    Do I still need this ? Or is it redundant with the previous rule for https ?

    # BEGIN rlrssslReallySimpleSSL rsssl_version[3.2.2]
    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{HTTP:X-Forwarded-Proto} !https
    RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
    </IfModule>
    # END rlrssslReallySimpleSSL
    #288934
    Mark
    Keymaster

    You can leave the Really Simple SSL rules in, the non-www to www rules only redirect non-www requests to https://. The Really Simple SSL rules make sure that direct www requests will also be redirected to https://.

Viewing 9 posts - 1 through 9 (of 9 total)
  • You must be logged in to reply to this topic.