redirect - Wordpress (behind HAProxy and Jetty), not multisite, in sub folder - and enwp-admin keeps redirecting to wp-admin

admin2025-01-07  6

I am using an unusual setup to host 3 Wordpress installations on CentOS 8 Linux.

In front I have HAProxy (to offload TLS), then I have Jetty configured for FastCGI and php-fpm and finally Wordpress.

I am using the Wordpress around a word game written in Pixi.js.

For several years now I have been using 3 different IP-addresses and 3 different domain names for the 3 language versions of my game: en, de, ru.

However my word game is not successful, so I have decided to give up the additional domain names and IP addresses and just use folders to serve my game:

  • wordsbyfarber/en
  • wordsbyfarber/de
  • wordsbyfarber/ru

This has worked well, I am not using multisite and I have set

define('WP_HOME', '');
define('WP_SITEURL', '');

in en/wp-config.php (same for de and ru) and also in the dashboard:

And already you can see my problem in the above screenshot:

While the user-facing websites work ok, the admin dashboard at /en/wp-admin/ immediately redirects to /wp-admin which is not ok, since I am not using multisite.

I have tried to solve the problem myself and searched a lot in the docs etc.

Also I wondered, who is doing the redirect, is it JS or PHP?

It seems to me that this is done by the PHP code of Wordpress, which for some reason sends a new Location header:

As you can see in the above screenshot, when using wget - for some reason Wordpress would remove /en string from /en/wp-admin path and redirect to the new location.

Why is it doing so and how to stop it?

I have tried to search in Wordpress source code with:

find ./en/ -iname \*.php| xargs grep -riw redirect_to

but wasn't able to find the reason yet.

UPDATE: I do not have any .htaccess file, because I am using Jetty configured for FastCGI with the following config file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
    ".dtd">
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">

    <New id="root" class="java.lang.String">
        <Arg>/var/www/html/wordsbyfarber/en</Arg>
    </New>

    <Set name="contextPath">/en</Set>
    <Set name="resourceBase"><Ref refid="root" /></Set>

    <Set name="welcomeFiles">
        <Array type="string">
                <Item>index.php</Item>
                <Item>index.html</Item>
        </Array>
    </Set>

    <Call name="addFilter">
        <Arg>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</Arg>
        <Arg>/*</Arg>
        <Arg>
            <Call name="of" class="java.util.EnumSet">
                <Arg><Get name="REQUEST" class="javax.servlet.DispatcherType" /></Arg>
            </Call>
        </Arg>
        <Call name="setInitParameter">
            <Arg>files</Arg>
            <Arg>$path /index.php?p=$path</Arg>
        </Call>
    </Call>

    <Call name="addServlet">
        <Arg>
            <New class="org.eclipse.jetty.servlet.ServletHolder">
                <Arg>default</Arg>
                <Arg>
                    <Call name="forName" class="java.lang.Class">
                        <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                    </Call>
                </Arg>
                <Call name="setInitParameter">
                    <Arg>dirAllowed</Arg>
                    <Arg>false</Arg>
                </Call>
                <Call name="setInitParameter">
                    <Arg>gzip</Arg>
                    <Arg>true</Arg>
                </Call>
            </New>
        </Arg>
        <Arg>/</Arg>
    </Call>

    <Call name="addServlet">
        <Arg>org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet</Arg>
        <Arg>*.php</Arg>
        <Call name="setInitParameter">
            <Arg>proxyTo</Arg>
            <Arg>http://localhost:9000</Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>prefix</Arg>
            <Arg>/</Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>scriptRoot</Arg>
            <Arg><Ref refid="root" /></Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>scriptPattern</Arg>
            <Arg>(.+?\\.php)</Arg>
        </Call>
    </Call>
</Configure>

I am using an unusual setup to host 3 Wordpress installations on CentOS 8 Linux.

In front I have HAProxy (to offload TLS), then I have Jetty configured for FastCGI and php-fpm and finally Wordpress.

I am using the Wordpress around a word game written in Pixi.js.

For several years now I have been using 3 different IP-addresses and 3 different domain names for the 3 language versions of my game: en, de, ru.

However my word game is not successful, so I have decided to give up the additional domain names and IP addresses and just use folders to serve my game:

  • wordsbyfarber.com/en
  • wordsbyfarber.com/de
  • wordsbyfarber.com/ru

This has worked well, I am not using multisite and I have set

define('WP_HOME', 'https://wordsbyfarber.com/en');
define('WP_SITEURL', 'https://wordsbyfarber.com/en');

in en/wp-config.php (same for de and ru) and also in the dashboard:

And already you can see my problem in the above screenshot:

While the user-facing websites work ok, the admin dashboard at /en/wp-admin/ immediately redirects to /wp-admin which is not ok, since I am not using multisite.

I have tried to solve the problem myself and searched a lot in the docs etc.

Also I wondered, who is doing the redirect, is it JS or PHP?

It seems to me that this is done by the PHP code of Wordpress, which for some reason sends a new Location header:

As you can see in the above screenshot, when using wget - for some reason Wordpress would remove /en string from /en/wp-admin path and redirect to the new location.

Why is it doing so and how to stop it?

I have tried to search in Wordpress source code with:

find ./en/ -iname \*.php| xargs grep -riw redirect_to

but wasn't able to find the reason yet.

UPDATE: I do not have any .htaccess file, because I am using Jetty configured for FastCGI with the following config file:

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN"
    "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure class="org.eclipse.jetty.servlet.ServletContextHandler">

    <New id="root" class="java.lang.String">
        <Arg>/var/www/html/wordsbyfarber.com/en</Arg>
    </New>

    <Set name="contextPath">/en</Set>
    <Set name="resourceBase"><Ref refid="root" /></Set>

    <Set name="welcomeFiles">
        <Array type="string">
                <Item>index.php</Item>
                <Item>index.html</Item>
        </Array>
    </Set>

    <Call name="addFilter">
        <Arg>org.eclipse.jetty.fcgi.server.proxy.TryFilesFilter</Arg>
        <Arg>/*</Arg>
        <Arg>
            <Call name="of" class="java.util.EnumSet">
                <Arg><Get name="REQUEST" class="javax.servlet.DispatcherType" /></Arg>
            </Call>
        </Arg>
        <Call name="setInitParameter">
            <Arg>files</Arg>
            <Arg>$path /index.php?p=$path</Arg>
        </Call>
    </Call>

    <Call name="addServlet">
        <Arg>
            <New class="org.eclipse.jetty.servlet.ServletHolder">
                <Arg>default</Arg>
                <Arg>
                    <Call name="forName" class="java.lang.Class">
                        <Arg>org.eclipse.jetty.servlet.DefaultServlet</Arg>
                    </Call>
                </Arg>
                <Call name="setInitParameter">
                    <Arg>dirAllowed</Arg>
                    <Arg>false</Arg>
                </Call>
                <Call name="setInitParameter">
                    <Arg>gzip</Arg>
                    <Arg>true</Arg>
                </Call>
            </New>
        </Arg>
        <Arg>/</Arg>
    </Call>

    <Call name="addServlet">
        <Arg>org.eclipse.jetty.fcgi.server.proxy.FastCGIProxyServlet</Arg>
        <Arg>*.php</Arg>
        <Call name="setInitParameter">
            <Arg>proxyTo</Arg>
            <Arg>http://localhost:9000</Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>prefix</Arg>
            <Arg>/</Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>scriptRoot</Arg>
            <Arg><Ref refid="root" /></Arg>
        </Call>
        <Call name="setInitParameter">
            <Arg>scriptPattern</Arg>
            <Arg>(.+?\\.php)</Arg>
        </Call>
    </Call>
</Configure>
Share Improve this question edited Aug 11, 2021 at 11:56 Alexander Farber asked Aug 8, 2021 at 15:03 Alexander FarberAlexander Farber 892 silver badges20 bronze badges 3
  • 1 Have you used a database migration tool? In addition to the WP_HOME and WP_SITEURL options, WP tends to store URLs in serialized arrays throughout the database. Since they're serialized, you want to do more than a simple search and replace, so there are various plugins and WP-CLI commands to do this safely. – WebElaine Commented Aug 13, 2021 at 21:01
  • I have not used the migration tool, do you happen to know in which SQL table the URLs are stored? – Alexander Farber Commented Aug 14, 2021 at 7:24
  • They're stored in multiple tables. Look for a database migration plugin or service which will guide you through the steps needed to update them all safely (after you've taken a backup). – WebElaine Commented Aug 16, 2021 at 20:21
Add a comment  | 

3 Answers 3

Reset to default 0

Do you happen to have PHPMyAdmin or Adminer or a similar tool installed in your web server? You could easily run a search & replace. I'd recommend running a search and see if all the matching records make sense. Then, run a search & replace. As @WebElaine mentioned, WP tends to store the URLs in several places, including some plugins, so it is not always a straight answer.

These URLs are stored in [prefix]_options (generally wp_options) table. But as soon as you define WP_HOME and SITE_URL in config file, these options automatically get disabled in admin.

To me this issue doesn't seems to be wordpress related, rather it appears to be something in your jetty config for fastcgi.

You can try "force" WordPress to use your manually defined site URL. Add this code to your wp-config.php. This method is not the best fix but your case is like an emergency :D

define('WP_HOME', 'https://yourwebsite.com/en');
define('WP_SITEURL', 'https://yourwebsite.com/en');

According to WordPress "Changing The Site URL" page

This is not necessarily the best fix, it’s just hard-coding the values into the site itself. You won’t be able to edit them on the General settings page anymore when using this method.

转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1736253509a128.html

最新回复(0)