Desktopserver本地localhost报404错误,无法访问WordPress站点求原因
Hey there, let's break down possible reasons and fixes for that 404 error when accessing your local WordPress site via DesktopServer—since restarting XAMPP and the database didn't do the trick, let's dig deeper:
Check Your Site's Permalink Settings
Permalinks often get messed up after server restarts or configuration shifts. Try accessing your WordPress admin directly vialocalhost/your-site/wp-admin(if the front end throws a 404). Once logged in, head to Settings > Permalinks, pick any option except "Plain" (like "Post Name"), and click "Save Changes". This refreshes the.htaccessfile that handles URL routing for your site.Verify DesktopServer's Site Configuration
Open DesktopServer and confirm your site is marked as "Running". Double-check the local domain (e.g.,yoursite.local) matches exactly what you're typing in the browser. Sometimes DesktopServer fails to register a site properly during setup—try stopping and restarting just that specific site within DesktopServer (not just the global XAMPP services).Check
.htaccessFile Permissions and Content
Navigate to your site's root folder (usually inC:\xampp\htdocs\your-siteor DesktopServer's dedicated sites directory). Make sure the.htaccessfile exists and has the correct WordPress rewrite rules. If it's missing, create a new file with this content:# BEGIN WordPress <IfModule mod_rewrite.c> RewriteEngine On RewriteBase /your-site/ RewriteRule ^index\.php$ - [L] RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteRule . /your-site/index.php [L] </IfModule> # END WordPressReplace
/your-site/with your actual site's subdirectory (or use/if it's the root site). Also, ensure the file has read/write permissions for the server user.Confirm Apache's Mod_Rewrite is Enabled
DesktopServer depends on Apache's mod_rewrite module for pretty permalinks. Open XAMPP's Apache config file (httpd.conf), search formod_rewrite.so, and make sure the line isn't commented out (remove the#at the start if it is). Restart Apache after making this change.Check Hosts File Entries
For custom local domains likeyoursite.local, your computer needs to map that domain to127.0.0.1. Open your hosts file:- Windows:
C:\Windows\System32\drivers\etc\hosts - macOS/Linux:
/etc/hosts
Ensure there's a line like:
127.0.0.1 yoursite.localIf it's missing, add it (you might need admin rights to save), then flush your DNS cache: run
ipconfig /flushdnson Windows, orsudo dscacheutil -flushcacheon macOS.- Windows:
Test for Conflicting Plugins/Themes
A misbehaving plugin or theme can break URL routing. Rename thepluginsfolder in your site'swp-contentdirectory toplugins-disabled—if the site loads, you know a plugin is the issue. Enable them one by one to find the culprit. Do the same for thethemesfolder (rename tothemes-disabledand switch to a default theme like Twenty Twenty-Four via wp-admin if you can access it).
内容的提问来源于stack exchange,提问作者Bilal Sagir

