0

I have a WP installation that needs moving to a new site URL.

I have tried the usual methods listed on this codex. All of them produce the same problem. When I hit a link like this on the site:

<a href="https://site.mydomain.com/path/to/post">

The web server receives says:

The requested URL /path/to/post/ was not found on this server.

This is even if I paste the URL into the browser.

Note that some URLs DO work, for example to this CSS file:

http://site.mydomain.com/wp-includes/css/dist/block-library/style.min.css?ver=5.1.1

But NOT to blog posts.

EDIT with more info

When I view the source of the pages, I see that all hrefs are in fact correct. However, when clicked on, the links to the posts (but not to CSS files) are missing the "http://" prefix and are instead rendered as server-root relative URLs.

So my change to the siteurl option is being made, but something about the site in question is breaking some (but not all) URLs.

I have since tried a vanilla fresh install of WP and changed the siteurl for that at it does NOT exhibit this problem so I assume it's something in the WP install for this site.

Further forensics

The problem persists even when I try the following:

  • Removing all .htaccess files
  • Deactivating all plugins
  • Viewed using incognito mode.
  • Using another web browser to load the site (had been using Chrome, installed and used a fresh installation of Firefox)
  • Switching to a different theme (twentynineteen)
  • Putting one of the broken URLs into a plain .html test file
  • Welcome to WordPress Stack Exchange! We love to help. Have you also already tried wp search-replace http://old-example.com http://new-example.com --all-tables? And have you also tried define('RELOCATE', TRUE); define('WP_HOME', 'http://new-example.com'); define('WP_SITEURL', 'http://new-example.com'); in wp-config.php? – leymannx May 1 at 17:27
  • Thanks @leymannx - I have added more information about that to my question. – TommyPeanuts May 1 at 19:09
0

The easiest (and proper, IMHO) was is to make changes to the wp-options table. Using the update_option in the wp-config.php is not the proper way to do it. (And I'm not a big fan of changing the values in the wp-config.php file.) It's possible that adding a trailing slash might help (depends on your hosting and htaccess settings).

See the Codex for help with changing the site url. https://codex.wordpress.org/Moving_WordPress

And you will need to use a search/replace process to change any hard links to the old place in your database. I use the "Better Search and Replace" plugin, which works quite well. (Backups are good before doing changes.)

  • Thanks, but the issue is not that the change isn't being made, but that it's not being implemented properly. See my edits to my question. – TommyPeanuts May 1 at 19:10
  • Perhaps changes/updates to your htaccess to properly rewrite things? Or this is a theme problem (what if you use one of the '20' themes?)? Does this happen on another computer? or in a Private Browsing session (cache problem? cloud-cache problem?) If the wp-options table is correct, and you are using a standard wp-config.php file (no customizations there), then this sounds more like a theme problem. – Rick Hellewell May 1 at 19:41
  • No .htaccess file is present. When I try another theme the same problem occurs. – TommyPeanuts May 1 at 21:28
  • What exactly does the HREF look like in the source code of the generated page? (You can replace the domain name with example.com if you need to obfuscate.) And, what if you put in a standard WP htaccess (found in the Codex)? – Rick Hellewell May 1 at 23:02
  • Also, do a reinstall WP via the Admin, Update screen. Just in case there is some weird code in the WP code files. – Rick Hellewell May 1 at 23:02
0

Drop the existing database. Import it again and try updating links with the following queries:

UPDATE wp_options SET option_value = replace(option_value, 'http://www.oldurl', 'http://www.newurl') WHERE option_name = 'home' OR option_name = 'siteurl';

UPDATE wp_posts SET guid = replace(guid, 'http://www.oldurl','http://www.newurl');

UPDATE wp_posts SET post_content = replace(post_content, 'http://www.oldurl', 'http://www.newurl');

UPDATE wp_postmeta SET meta_value = replace(meta_value,'http://www.oldurl','http://www.newurl');

Reference : Change and Update WordPress URLS in Database When Site is Moved to new Host

  • Done - but exactly the same problem occurs. Again, it's NOT that the siteurl etc. isn't being changed. It is, because viewing source in the browser shows that it is. But when the links to the posts are followed, the request that goes to the server lacks the "http://". I'll clarify the problem more in the question. – TommyPeanuts May 1 at 21:17
0

The permalink structure was set to "Post name":

http://site.mydomain.com/sample-post/

Setting it to "Plain" http://site.mydomain.com/?p=123, fixed the issue.

I do not know why post name was causing a problem. While the WP install was moved to another web server, there were no Apache rewrite rules in the vhost config and all other setting are the same. I am also at a loss to explain how the post name permalink structure in the original installation was working in the first place.

The End

Wordpress is weird and strange, and I will never understand it. Thank you all for your help however, for it is much appreciated.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.