0

After moving my Wordpress installation to a subfolder, I went to the wp_options table to edit the site_url and home. However, after the website is loaded even once, the home is reset to the actual path.

Let's say the site used to be https://example.com and I moved the Wordpress installation to https://example.com/shop. Whatever I change the home to in the DB, it resets to https://example.com/shop after a page load. I can even set it to apple.com, after a page load it resets.

Same happens if I go to Settings -> General and try to update the field. After I hit save and the page reloads, the value is already reset to the actual path.

The same happens if I deactivate all plugins. Same happens if I migrate all tables to a new database.

So the only way to achieve my wanted result now is via the wp-config.php settings where I have set:

define( 'WP_HOME', 'https://example.com/' ); define( 'WP_SITEURL', 'https://example.com/shop/' ); 

I'd like to however fix this sh*t on the DB level so I know everything is solid. I also want to implement WP Multisite so I want to be sure all is good.

1 Answer 1

1

Caveat found, it was the first function in a hosting provider installed plugin...

 public function __construct() { /* * Updates the home and siteurl on every website visit between www or non-www. * This avoids endless redirection conflicts when trying to configure website redirection from control panel or * when configuring a htaccess based redirection. * For example when you set the WP siteurl in WP to be www.example.com, then WP can begin to redirect non-www * URLs to www URLs. And when you try to configure non-www URL to be used through the control panel, then it * will conflict with that redirection that the WP does (redirection configured from control panel tries to * redirect from http://www.example.com to http://example.com and at the same time WP tries to redirect from * http://example.com to http://www.example.com, causing a redirection loop). This siteurl updating hack here * resolves this. * This means that some content might be saved into WP database with www prefixed URLs and some not, in case no * single version has been configured. This however shouldn't be a problem as long as both URLs work. */ $url = set_url_scheme('http://' . $_SERVER['HTTP_HOST']); $siteurl = get_option('siteurl'); $current_url = parse_url($url); $current_siteurl = parse_url($siteurl); $current_url_host = preg_replace('/^www\./', '', $current_url['host']); $current_siteurl_host = preg_replace('/^www\./', '', $current_siteurl['host']); // Only update if the domain name is the same and only using with or without www is the difference $compare_url_host = idn_to_ascii($current_url_host); $compare_siteurl_host = idn_to_ascii($current_siteurl_host); // Make sure that the website is viewed from the same domain that is defined in the WP settings if (strcasecmp($compare_url_host, $compare_siteurl_host) == 0) { // Check if there is a difference in the host URL (does it have www prefix difference between current // URL and WP URL). If there is, save the new URL to WP settings. if ($url != $siteurl) { $new_siteurl = $current_siteurl['scheme'] . '://' . $current_url['host'] . (isset($current_siteurl['path']) ? $current_siteurl['path'] : ''); update_option('siteurl', $new_siteurl); update_option('home', $new_siteurl); } } } 

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.