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

.htaccess配置异常:错误地址请求返回500而非404错误

Troubleshooting Your .htaccess 404 → 500 Error Issue

Hey there, let's break down what's going wrong with your .htaccess setup and fix it step by step!

First off, the snippet you shared has a clear syntax error in your RewriteRule—this is almost certainly the root cause of the 500 internal server error instead of the expected 404. Let's tackle this first:

1. Fix the Broken Non-WWW to WWW Redirect

Your redirect rule is incomplete: those trailing ... are invalid Apache syntax, and the rule is missing critical flags that ensure it works correctly. Here's the corrected version:

# Enable rewrite engine
RewriteEngine On

# Redirect non-www to www domain
RewriteCond %{HTTP_HOST} ^thehalcyon.tk [NC]
RewriteRule ^(.*)$ http://www.thehalcyon.tk/$1 [R=301,L]
  • The [R=301,L] flags are essential: R=301 marks this as a permanent redirect (good for SEO), and L tells Apache to stop processing further rules after this one (prevents unexpected conflicts).
  • We removed the stray ? and invalid ... that were causing Apache to fail parsing the rule.

2. Verify Your Custom 404 Configuration

Make sure your ErrorDocument path is correctly defined. If your custom 404 file (e.g., 404.html) lives in your site's root directory, the line should look like this:

ErrorDocument 404 /404.html
  • Always use an absolute path starting with /—this ensures Apache looks in the correct root directory for the error page. A missing or mispathing error file can also trigger a 500 error.

3. Debug Step-by-Step to Confirm Fixes

If you're still seeing issues after applying the above, narrow down the problem with these checks:

  • Temporarily comment out the Rewrite rules (add # at the start of each Rewrite line) and test a non-existent URL. If the custom 404 loads correctly, the issue was definitely in the rewrite logic.
  • Scan your full .htaccess for other syntax errors—even a missing bracket or extra character can crash Apache's rewrite engine.
  • Double-check that your server allows .htaccess overrides (your hosting control panel or virtual host config should have AllowOverride All set for your site directory).

Once you've applied these fixes, test again by visiting a made-up URL on your site—you should see your custom 404 page instead of a 500 error.

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 10:53:17