regex - 重定向过多 - 使用 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 的重写时也会发生此错误。
有什么我想念的想法吗?
解决方案
您将获得太多重定向,因为即使您重定向到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
。
确保在测试此更改时清除浏览器缓存。
推荐阅读
- python - 为包含 Swig 对象的 Python 对象创建复制类方法
- c# - 错误:无法访问已处置的对象。对象名称:'ShellStream'
- python - 为什么我不能得到 pafy 的 youtube 视频的标题
- r - RS-DBI 驱动程序:(无法在数据库名称“lahman”上连接 user@localhost:5432:致命:数据库“lahman”不存在
- wordpress - 您的服务器正在运行 PHP 版本 5.4.45,但 WordPress 5.2.2 至少需要 5.6.20
- google-apps-script - 性别化名称 API,达到请求限制 - 无法让谷歌表格自定义功能工作
- javascript - Quasar cordova-plugin-device - 错误“设备”未定义
- html - 如何删除顶部的白条?
- zend-framework - 如何从另一个模块提供服务?
- c# - 如何将信息从视图传递到控制器作为参数