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

.htaccess的RewriteRule规则返回404错误求助

解决.htaccess RewriteRule返回404的问题

你的规则出现404,主要是路径匹配逻辑和正则写法的问题,按以下步骤修改:

  1. 添加RewriteBase指定目录
    在RewriteEngine On后添加RewriteBase /df-talents/,确保重写规则基于当前子目录路径匹配,避免服务器解析时的路径混乱。

  2. 修正静态文件排除规则的正则
    原规则的正则未匹配后缀结尾,可能误排除或漏排除文件,改成带$的精准匹配,同时加NC忽略大小写:

    RewriteCond %{REQUEST_URI} !\.(html|js|css)$ [NC]
    RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|txt|ico|webp)$ [NC]
    RewriteCond %{REQUEST_URI} !\.(eot|ttf|woff)$ [NC]
    
  3. 调整RewriteRule匹配逻辑

    • 如果需要内部转发(地址栏URL不变,服务器返回index.html内容),用这条规则:
      RewriteRule ^.*classes.*$ index.html [NC,L]
      
    • 如果需要外部重定向(地址栏URL直接变为/df-talents/index.html),添加R=302标记(临时重定向,永久重定向用R=301):
      RewriteRule ^.*classes.*$ /df-talents/index.html [NC,L,R=302]
      

完整的.htaccess示例(内部转发版本)

RewriteEngine On
RewriteBase /df-talents/

RewriteCond %{REQUEST_URI} !\.(html|js|css)$ [NC]
RewriteCond %{REQUEST_URI} !\.(jpg|jpeg|png|gif|txt|ico|webp)$ [NC]
RewriteCond %{REQUEST_URI} !\.(eot|ttf|woff)$ [NC]

RewriteRule ^.*classes.*$ index.html [NC,L]

额外检查

确认服务器配置中,/df-talents目录的AllowOverride参数已设置为All,否则.htaccess文件的规则不会被服务器解析。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.17 14:20:49