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

同一URL在Chrome与Firefox中响应异常问题求助

问题排查与解决

核心原因分析

  1. Rewrite规则顺序错误:你的.htaccess里将请求转发到index.php的规则放在了www跳转规则之前,且该规则未排除真实存在的文件/目录,导致所有请求(包括www跳转后的请求)都被强制转发到index.php。加上若服务器实际部署在子目录(如/kunden/homepages/45/d913608981/htdocs/example/),但RewriteBase设为/,会引发路径拼接错误。
  2. Chrome的301缓存特性:之前错误的重定向规则被Chrome缓存了永久301重定向,即使你修改了规则,Chrome仍会沿用旧缓存;而Firefox要么未缓存该路径,要么缓存已过期,因此表现正常。
  3. 缺少文件/目录校验:未注释的index.php转发规则没有先判断请求的文件/目录是否存在,导致静态资源也被转发到index.php,进一步加重路径异常问题。

修复步骤

1. 调整Rewrite规则顺序与配置

修改.htaccess中的规则逻辑,正确顺序应为:先处理域名跳转,再放行真实文件/目录,最后转发请求到index.php。同时修正RewriteBase以匹配实际部署路径:

# Disable directory browsing
Options -Indexes

# ----------------------------------------------------------------------
# Rewrite engine
# ----------------------------------------------------------------------

# Turning on the rewrite engine is necessary for the following rules and features.
# FollowSymlinks must be enabled for this to work.
<IfModule mod_rewrite.c>
    Options +FollowSymlinks
    RewriteEngine On

    # 修正RewriteBase:若部署在/example子目录,改为/example/(需匹配实际路径)
    RewriteBase /example/

    # Rewrite "www.example.com -> example.com"
    RewriteCond %{HTTPS} !=on
    RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
    RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]

    # 若请求的是真实文件/目录,直接放行
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # 转发请求到CodeIgniter入口文件
    RewriteRule ^(.*)$ index.php/$1 [QSA,L]

    # Ensure Authorization header is passed along
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    ErrorDocument 404 index.php
</IfModule>

# Disable server signature start
ServerSignature Off
# Disable server signature end
SetEnv ci_environment DEVELOPMENT

2. 清除Chrome的301缓存

Chrome会长期缓存永久重定向,需手动清除:

  • 打开Chrome开发者工具(F12),切换到Network标签,勾选Disable cache后刷新页面
  • 或在Chrome设置中清除「缓存的图片和文件」

3. 验证部署路径匹配

确保RewriteBase与网站实际部署路径一致:如果网站物理根目录是/kunden/homepages/45/d913608981/htdocs/example/,则URL根对应/example/,RewriteBase必须设为/example/,否则服务器会错误拼接物理路径,导致重复。

浏览器表现差异的本质

Firefox对301缓存的默认有效期更短,或你之前未在Firefox访问过错误路径,因此没有缓存旧的重定向规则;而Chrome会持久化缓存301重定向,直到缓存过期或手动清除,所以即使服务器端修复了规则,Chrome仍会沿用旧缓存。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.17 07:05:58