WordPress链接跳转404错误求助:使用site_url生成子页面链接异常
/projekti/ Link 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 thepage-{slug}.phptemplate. 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)
- Its slug is exactly
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.htaccessfile 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
.htaccessfile
Ensure your site’s root.htaccessfile 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 WordPressIf 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:- Switching to a default WordPress theme (like Twenty Twenty-Four)
- 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 namedpage-projekti.php(case-sensitive on Linux servers—so avoid capital letters likePage-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

