You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Apache本地开发环境下非纯固定链接返回404问题求助

Hey there, let's work through this permalink issue you're hitting with your local XAMPP setup. I've dealt with similar headaches when switching to "Post name" permalinks, so here are the most common fixes to get your pages working again:

  • Enable mod_rewrite in Apache
    This is the #1 culprit for permalink 404s on XAMPP. Here's how to turn it on:

    1. Open your XAMPP Control Panel, click the "Config" button next to Apache, then select httpd.conf.
    2. Search for the line starting with #LoadModule rewrite_module modules/mod_rewrite.so — remove the # at the beginning to uncomment it.
    3. Save the file, then restart Apache from the XAMPP Control Panel.
  • Fix your .htaccess file
    WordPress needs a properly configured .htaccess to handle "Post name" permalinks. Try these steps:

    1. First, back up your existing .htaccess file (if it exists) in your WordPress root directory.
    2. Go to your WordPress admin dashboard → Settings → Permalinks. Switch back to "Plain" permalinks, save changes, then switch back to "Post name" and save again. This forces WordPress to regenerate the correct rewrite rules.
    3. If WordPress can't write to .htaccess automatically (common on local setups), add these rules manually:
      # 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
      
      Note: If your WordPress site is in a subfolder (e.g., localhost/my-site), update RewriteBase / to RewriteBase /my-site/ and change the last line to RewriteRule . /my-site/index.php [L].
  • Verify custom post type rewrite settings
    Even though your custom post types are working, a misconfigured rewrite parameter could interfere with other pages. Check your custom post type registration code (usually in functions.php or a custom plugin):

    register_post_type('your_cpt_slug', array(
        // ... other settings
        'rewrite' => array(
            'slug' => 'your-cpt-slug', // Make sure this doesn't clash with page/post slugs
            'with_front' => true // Set to false only if you want to skip the base permalink structure
        ),
        // ...
    ));
    

    If you made changes here, save the file and go back to Settings → Permalinks to resave your settings (this flushes rewrite rules).

  • Check file permissions
    On some systems, WordPress might not have permission to write to .htaccess.

    • For Windows: Right-click the .htaccess file → Properties → Security and give your user account "Write" permissions.
    • For Mac/Linux: Open Terminal, navigate to your WordPress root folder, and run chmod 664 .htaccess to set the correct permissions.
  • Flush rewrite rules manually
    Sometimes WordPress caches old rewrite rules. If the above steps don't work, add this line temporarily to your theme's functions.php file, load any page on your site, then remove it:

    flush_rewrite_rules();
    

    Important: Don't leave this line in permanently — it runs on every page load and will slow down your site.

Most of the time, enabling mod_rewrite and fixing .htaccess resolves this issue. If you're still seeing 404s, double-check that none of your page slugs conflict with custom post type slugs or WordPress default routes.

内容的提问来源于stack exchange,提问作者Cactusman07

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.19 10:36:10