WordPress staging子域名根页面跳转至主站/php 404问题求助
Hey Jon, let's work through this root page redirect problem together. Since your staging site's wp-admin and individual pages (like /sample-page/) load fine, the issue is almost certainly related to site URL configuration, rewrite rules, or server defaults. Here's what to check step by step:
1. Verify WordPress Site URL Settings
First, confirm your staging site's core URL settings are pointing correctly:
- Log into your staging wp-admin, go to Settings > General
- Make sure both WordPress Address (URL) and Site Address (URL) are set to
https://staging.website.com(adjust HTTP/HTTPS as needed) - If you can't access the settings page or changes don't stick, edit your
wp-config.phpfile in the staging root directory and add these lines above the/* That's all, stop editing! Happy publishing. */comment:define('WP_HOME','https://staging.website.com'); define('WP_SITEURL','https://staging.website.com'); - Save the file, then clear your browser cache and any WordPress cache (if using a plugin like WP Rocket or W3 Total Cache)
2. Check .htaccess Rewrite Rules
Your staging site's .htaccess file might have incorrect rewrite rules causing the redirect:
- Access your staging server via FTP/SFTP or cPanel File Manager (enable hidden files to see
.htaccess) - Replace any existing rules with the default WordPress rewrite rules (back up the original first):
# 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 - Save the file and test accessing
staging.website.comagain
3. Confirm Server Default Document Configuration
Sometimes servers prioritize non-PHP files or have missing defaults:
For Apache:
Add this line to your staging .htaccess to ensure index.php is the first default file:
DirectoryIndex index.php index.html index.htm
For Nginx:
Check your staging site's Nginx configuration file (usually in /etc/nginx/sites-available/) and ensure the location / block includes index.php first:
location / { index index.php index.html index.htm; try_files $uri $uri/ /index.php?$args; }
- Restart your web server (Apache:
sudo systemctl restart apache2; Nginx:sudo systemctl restart nginx) after making changes
4. Clear Cache & Disable CDN (If Applicable)
Cached redirects can persist even after fixing settings:
- If you use a CDN for your domain, purge all CDN cache for the staging subdomain
- Temporarily disable any WordPress caching plugins on the staging site and test again
- Clear your browser's cache and try accessing the root page in incognito mode to rule out local caching
5. Check Server-Level Redirects
Some hosting control panels (like cPanel) let you set redirects at the server level:
- Log into your hosting account, look for a Redirects tool
- Check if there's an active redirect rule pointing
staging.website.comtowebsite.com/php - Delete any such rule if it exists
If none of these steps resolve the issue, reach out to your hosting provider—they might have a server-level configuration (like a global redirect rule) that's overriding your staging site's settings.
内容的提问来源于stack exchange,提问作者Jon Williams

