admin管理员组

文章数量:1429613

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="">

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:

.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

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/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/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
Share Improve this question edited May 2, 2019 at 7:39 TommyPeanuts asked May 1, 2019 at 16:44 TommyPeanutsTommyPeanuts 1013 bronze badges 2
  • Welcome to WordPress Stack Exchange! We love to help. Have you also already tried wp search-replace http://old-example http://new-example --all-tables? And have you also tried define('RELOCATE', TRUE); define('WP_HOME', 'http://new-example'); define('WP_SITEURL', 'http://new-example'); in wp-config.php? – norman.lol Commented May 1, 2019 at 17:27
  • Thanks @leymannx - I have added more information about that to my question. – TommyPeanuts Commented May 1, 2019 at 19:09
Add a comment  | 

3 Answers 3

Reset to default 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/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.)

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

The permalink structure was set to "Post name":

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

Setting it to "Plain" http://site.mydomain/?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.

本文标签: wp cliWP changes siteurlbut some URLs then don39t work