首页 > 解决方案 > 重定向过多 - 使用 htaccess 将 IE 重定向到特定页面

问题描述

我正在尝试使用 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 的重写时也会发生此错误。

有什么我想念的想法吗?

标签: regexapache.htaccessmod-rewrite

解决方案


您将获得太多重定向,因为即使您重定向到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

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


推荐阅读