修改SiteURL与Home后WordPress站点故障,按规范操作仍未解决
Hey there, sorry to hear you're stuck after going through the usual checklist to update your WordPress site URL from www.mysite.com/wordpress to www.mysite.com/blog. Let's dive into some less obvious fixes that might be holding you back:
Check for hardcoded URLs in themes/plugins
A lot of themes and lazy-coded plugins skip WordPress's native URL functions (likesite_url()orhome_url()) and hardcode the old URL directly. Use a search-replace tool to clean these up:- If you have WP-CLI access, run:
wp search-replace 'www.mysite.com/wordpress' 'www.mysite.com/blog' --skip-columns=guid
(The--skip-columns=guidflag is critical—don't overwrite post GUIDs, they're permanent identifiers.) - Without WP-CLI, use phpMyAdmin to search tables like
wp_posts,wp_postmeta, andwp_optionsfor the old URL, replacing instances where it appears (again, avoid touching theguidcolumn).
- If you have WP-CLI access, run:
Verify server configuration matches your setup
The fix here depends on whether you moved WordPress files to a/blogdirectory or just want to map the URL to the existing/wordpressinstall:- If files stay in
/wordpress:
For Apache, update your root.htaccessto redirect/blogtraffic to the/wordpressdirectory:
For Nginx, add this location block to your server config:RewriteEngine On RewriteRule ^blog/(.*)$ /wordpress/$1 [L]location /blog { alias /path/to/your/wordpress; try_files $uri $uri/ /blog/index.php?$args; } - If you moved files to
/blog:
Double-check that your.htaccessis in the/blogdirectory with the correct rewrite base:
Also ensure Apache hasRewriteEngine On RewriteBase /blog/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /blog/index.php [L]AllowOverride Allset for the/blogdirectory (so.htaccessrules are applied), or Nginx's root points to the right path.
- If files stay in
Flush all caches
Caches are the #1 culprit for lingering old URLs:- Force-refresh your browser (Ctrl+Shift+R on Windows/Linux, Cmd+Shift+R on Mac) to clear local cache.
- Disable or flush any WordPress cache plugins (e.g., WP Rocket, W3 Total Cache) you're using.
- Purge server-side caches (like Varnish) or CDN caches if you have them set up.
Double-check wp-config.php and wp_options for hidden issues
- Confirm your
wp-config.phpdefines the URLs correctly (place these lines before the "stop editing" comment):
Don't forget to usedefine('WP_SITEURL', 'https://www.mysite.com/blog'); define('WP_HOME', 'https://www.mysite.com/blog');https://if your site uses SSL, and avoid trailing slashes unless you're sure you need them. - In
wp_options, check beyond justsiteurlandhome—look for fields likeupload_path,fileupload_url, or theme-specific options (e.g., logo URL, custom menu links) that might still reference the old URL.
- Confirm your
Check file permissions
Ensure your.htaccessfile has the correct permissions (usually644for Apache) so the server can read it. If you're on Apache, also confirm thatAllowOverride Allis enabled in your VirtualHost or directory config—without this,.htaccessrules won't take effect.
Give these steps a shot in order—most of the time, it's a hidden hardcoded URL, misconfigured server rule, or stubborn cache causing the issue.
内容的提问来源于stack exchange,提问作者cnu

