• Hi everyone,

    I have a client who is with a hosting company where existing entries in the wp-config.php file are not writeable as it has a write protection set up by the hosting company. Per default the hosting company sets the WP Home and Site URL to the same URL under which the WP installation is running.

    In most of the cases this is the desired setup. However, I need to connect a reverse proxy to the WP installation as the domain for WP should be a subdirectory of the main domain. On the main domain itself another non WP system is hosted and this is also running with a different hosting company. Thus, I need the reverse proxy. With the old hosting company I could achieve this easily as I just had to change the WP Site and Home URL in wp-config, so that it differs from the domain connected to the WP installation. That was all.

    Now with the new hosting company I cannot do this as I am not permitted to change the WP Site and Home URL in wp-config file because of the write lock. So my question is if there is any solution how I can change the WP Site and Home URL without having to change the two lines in the wp-config file. This is what I’ve tried so far:

    1. Changed WP Site and Home URL in the database
    This had no effect as constants in wp-config are getting prioritized.

    2. Edited theme’s functions.php file
    I added this:
    update_option( ‘siteurl’, ‘https://example.com’ );
    update_option( ‘home’, ‘https://example.com’ );
    This had no effect either as constants in wp-config are getting prioritized.

    3. Adding entries to wp-config.php file
    Although I cannot edit EXISTING entries in the wp-config what I can do is add additional entries which are always appended at the end of wp-config. So I tried the following:
    a) Adding WP Home and Site URL again –> no effect as the 1st entry is considered
    b) Writing update_option statements there –> site crashed

    4. Renaming wp-config file
    I created a file called custom-config.php and put my desired config in here. Then in wp-config I added the following as additional entry:
    include(‘/home/path/custom-config.php’);
    This had to effect either as the WP Site and Home URL are firstly defined in wp-config still before custom-config is included.

    Does anyone have another idea how I can overwrite the default set WP Site and Home URL without being able to delete these two rows? Of course I already contacted the hosting company and they said they cannot remove the write lock. I am glad for any suggestions.

    Thanks and best
    Nina

Viewing 1 replies (of 1 total)
  • Dion

    (@diondesigns)

    The first thing you should try is to convince your client to find a new hosting company. If that doesn’t work, then you could use the pre_option_siteurl and pre_option_home filters to trick WordPress into using your custom site and home URLs. The code must be added as early as possible in the WordPress loading process, perhaps as a must-use plugin. (One hopes the hosting company allows mu-plugins.)

Viewing 1 replies (of 1 total)

The topic ‘Overwrite WordPress Site and Home URL defined as PHP constants in wp-config’ is closed to new replies.