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

WordPress链接跳转404错误求助:使用site_url生成子页面链接异常

Hey there, sorry to hear your previously working link is throwing a 404! Let’s walk through the most common fixes for this issue step by step:

  • First, double-check your page’s slug and status
    WordPress uses the page’s slug to map to the page-{slug}.php template. Head to your WordPress dashboard, find the "Projekti" page, and confirm:

    • Its slug is exactly projekti (no extra characters, spaces, or typos)
    • The page is published (not set to Draft, Private, or Trashed)
  • Refresh your permalink settings
    This is the #1 fix for random WordPress 404s. Go to Settings → Permalinks in your dashboard, don’t change any settings—just click "Save Changes". This regenerates the .htaccess file and resets WordPress’s rewrite rules, which often gets corrupted after updates or plugin changes.

  • Verify the URL generated by site_url()
    Temporarily add a line to output the exact URL your code is generating:

    <?php 
    $projekti_url = site_url('/projekti/');
    echo "Generated URL: " . $projekti_url; 
    ?>
    

    Make sure the URL matches the actual permalink of your "Projekti" page. If it’s pointing to a wrong domain or has a typo (like /projekt/ instead of /projekti/), that’s the issue.

  • Check your .htaccess file
    Ensure your site’s root .htaccess file exists, has the correct permissions (usually 644), and contains the default 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
    

    If the file is missing or has incorrect content, replace it with the code above (just make sure to back up the original first!).

  • Rule out plugin or theme conflicts
    Recent plugin installs, updates, or theme changes can break permalinks. Try:

    1. Switching to a default WordPress theme (like Twenty Twenty-Four)
    2. Disabling all plugins
      Then test the link again. If it works, re-enable plugins one by one (or switch back to your theme) to find which one is causing the conflict.
  • Confirm your template file is correctly named
    Double-check that your theme folder has a file named page-projekti.php (case-sensitive on Linux servers—so avoid capital letters like Page-Projekti.php). Also, ensure the file has no syntax errors that might prevent WordPress from recognizing it.

Since the link worked before, the problem is almost certainly a broken rewrite rule, a changed page slug, or a recent conflict. Start with refreshing permalinks—it’s quick and solves most cases!

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.25 07:06:23