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

WordPress主题分页线上失效求助:本地正常线上返回404

Hey there, let's tackle this pagination 404 issue you're hitting after deploying your WordPress theme live—this is a super common gotcha when moving from local to production, so let's walk through the most likely fixes step by step.

Nine times out of ten, this is the quick fix. Local environments often handle rewrite rules smoothly, but live servers sometimes need a nudge to update them. Here's what to do:

  • Log into your live WordPress admin
  • Go to Settings > Permalinks
  • Don't change your current structure—just select a different one (like "Plain") and click "Save Changes"
  • Then switch back to your original permalink structure and save again

This forces WordPress to regenerate the rewrite rules that handle pagination URLs. If you're on an Nginx server (instead of Apache), you might need to add this rewrite rule to your server config:

location / {
    try_files $uri $uri/ /index.php?$args;
}

2. Fix Your Custom Query's Paged Parameter

If you're using a custom WP_Query for your post type, it's easy to mess up how the paged variable is passed. Make sure you're pulling the current page number correctly from the query vars, not hardcoding it:

// Get the current page number (use 'page' instead of 'paged' if this is a static front page)
$paged = (get_query_var('paged')) ? get_query_var('paged') : 1;

$custom_query_args = array(
    'post_type' => 'your_custom_post_type', // Replace with your CPT slug
    'posts_per_page' => 10, // Your posts per page setting
    'paged' => $paged // Critical: pass the paged variable here
);

$custom_query = new WP_Query($custom_query_args);

Also, don't forget to reset the query after your loop to avoid messing up other parts of the site:

wp_reset_postdata();

3. Clear All Caches (Server + Plugin)

Live sites often have caching layers that local environments don't—this can cache old, broken pagination URLs. Clear:

  • Any WordPress caching plugins (like WP Rocket, W3 Total Cache, or LiteSpeed Cache)
  • Server-level cache (check your hosting dashboard for options like "Purge Cache")
  • CDN cache (if you use Cloudflare, CloudFront, etc.)

After clearing, refresh your permalink settings again (step 1) to make sure new rules aren't cached.

If you're building pagination links manually with paginate_links(), incorrect base or format settings can break URLs. Here's a solid example to adapt:

echo paginate_links(array(
    'base' => get_pagenum_link(1) . '%_%', // Base URL for pagination
    'format' => 'page/%#%/', // Match your permalink structure (e.g., /page/2/)
    'current' => max(1, get_query_var('paged')), // Current active page
    'total' => $custom_query->max_num_pages, // Total number of pages from your query
    'prev_text' => '« Previous',
    'next_text' => 'Next »'
));

If your custom post type has a custom archive slug, adjust the base to match that URL (e.g., get_site_url() . '/custom-post-type/%_%').

5. Verify Custom Post Type Rewrite Rules

If you registered a custom post type, make sure you enabled rewrite rules and flushed them after deployment. When registering your CPT, ensure these settings are present:

register_post_type('your_custom_post_type', array(
    // Other CPT settings...
    'rewrite' => array(
        'slug' => 'custom-post-type', // Your CPT's URL slug
        'with_front' => false // Avoids adding your permalink base (like /blog/) to the CPT URL
    ),
    'has_archive' => true // Enables the archive page where pagination lives
));

To flush rewrite rules safely (don't put this in your main functions.php—it runs on every load), add this activation hook to your theme:

function my_theme_flush_rewrites() {
    flush_rewrite_rules();
}
add_action('after_switch_theme', 'my_theme_flush_rewrites');

Then reactivate your theme once to trigger the flush.

6. Check .htaccess Permissions (Apache Servers)

If WordPress can't write to your .htaccess file, it can't update rewrite rules. Connect to your server via FTP/SFTP, check if .htaccess exists, and:

  • If it doesn't, create it with the standard WordPress rewrite rules:
# 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
  • Set the file permissions to 644 (read/write for owner, read-only for others)

Start with steps 1 and 3 first—those fix most cases. If you're still stuck, share a snippet of your custom query and pagination code, and I can help narrow it down further!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.21 06:35:44