重定向太多 - 使用 htaccess 将 IE 重定向到特定页面

Too many redirects - redirecting IE to a specific page with htaccess

我正在尝试使用 htaccess 将 IE 用户重定向到特定页面。这是我到目前为止得到的:

<IfModule mod_rewrite.c>
    RewriteEngine on

    RewriteCond %{HTTP_USER_AGENT} ^.*Trident.*$
    RewriteRule (.*) /not-supported-browser.html [R=301,L]
</IfModule>

但是每当我使用 IE11 请求某些页面时,我都会收到“重定向太多”的错误。我将我的条件更改为 Firefox 和 Chrome,相同的行为所以我认为条件很好。

我正在使用 CMS,但当我删除我的 htaccess 中所有特定于 CMS 的重写时,也会发生此错误。

知道我遗漏了什么吗?

你会得到太多的重定向因为即使你重定向到not-supported-browser.html客户端浏览器保持不变并且第一个条件仍然成立。

您可以使用此规则来防止此行为:

RewriteEngine on

RewriteCond %{HTTP_USER_AGENT} Trident [NC]
RewriteRule !^not-supported-browser\.html$ /not-supported-browser.html [R=301,L,NC]

如果页面已经是 /not-supported-browser.html,否定模式 !^not-supported-browser\.html$ 将跳过重定向。

确保在测试此更改时清除浏览器缓存。