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
3 Answers
Reset to default 0The 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
版权声明:本文标题:wp cli - WP changes siteurl, but some URLs then don't work 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745532843a2662138.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
wp search-replace http://old-example http://new-example --all-tables
? And have you also trieddefine('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