WordPress子目录部署后线上页面异常,wp-admin报404求助
Hey Adrian, let's work through this step by step—this exact set of issues is super common when moving a local WordPress site to a live host, especially with subdirectory data setups and UK2's specific server configs. Here's how to fix each problem:
Your local WAMP setup uses localhost/[your-path] for asset URLs, but your live UK2 site is using your domain. WordPress is still trying to pull CSS/JS from your local server, which is why you only see plain text. Here are two reliable fixes:
- Option 1: Edit wp-config.php (fastest, no admin access needed)
Open your rootwp-config.phpfile and add these lines right above the/* That's all, stop editing! Happy publishing. */comment:
If your WordPress data (wp-content, wp-includes) lives in a subdirectory likedefine('WP_HOME', 'https://yourdomain.com'); define('WP_SITEURL', 'https://yourdomain.com');/wp-data, adjust WP_SITEURL tohttps://yourdomain.com/wp-data - Option 2: Update via Database (if wp-config tweaks don't stick)
Use UK2's phpMyAdmin tool to access your WordPress database, find thewp_optionstable, and update:- The
siteurlfield to your live domain (plus subdirectory path if applicable) - The
homefield to your live domain root
- The
UK2's Apache servers often need a specific .htaccess configuration, especially if you're using a subdirectory for data. Replace your root .htaccess file with this (adjust the RewriteBase line if your WordPress core is in a subdirectory):
# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /index.php [L] </IfModule> # END WordPress
If your WordPress core is hosted in a subdirectory like /wp-core, change RewriteBase / to RewriteBase /wp-core/
- Enable mod_rewrite: UK2 might have this disabled by default. Log into your cPanel, navigate to "Apache Modules" and ensure
mod_rewriteis checked. If you don't see this option, shoot UK2 support a quick message—they can enable it for you in minutes. - Check File Permissions: Set your
wp-contentfolder to permission755and all files inside to644. UK2's servers are strict about permissions, and incorrect settings can block asset loading entirely.
- After making these changes, hard-refresh your browser (Ctrl+Shift+R on most browsers) to force fresh asset loading—don't skip this, cached local assets will still break things.
- If wp-admin still throws a 404, add
define('FORCE_SSL_ADMIN', true);to your wp-config.php if you're using HTTPS (most UK2 plans include free SSL now). - If you're using a custom data subdirectory (not the default wp-content), double-check that your wp-config.php has the correct definitions for
WP_CONTENT_DIRandWP_CONTENT_URLpointing to your live subdirectory path.
内容的提问来源于stack exchange,提问作者Adrian lock

