apache - 如果通过 htaccess 具有特定路径,请不要重定向到 www
问题描述
我的 .htacess 文件中的以下规则,对于我的 Drupal 网站,将所有非 www URL 重定向到 www 版本。(例如:https://example.com
-> https://www.example.com
):
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
这很好用,但现在我想排除https://example.com/samltest/test
重定向到 www。我添加了以下内容:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{REQUEST_URI} !/samltest/ [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
但是现在当我到达时https://example.com/samltest/test
,它会重定向到https://example.com/index.php
. 有人对我做错了什么有任何想法吗?
解决方案
在 .htaccess 的顶部有这样的内容:
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteCond %{THE_REQUEST} !\s/+samltest [NC]
RewriteRule ^ http%{ENV:protossl}://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]
清除浏览器缓存后进行测试。
推荐阅读
- ip-address - Maxmind Geoip2 API vs 可下载数据库
- javascript - 父母和孩子之间的角度导航路由
- python - Python 不能正常使用回车符(新行)
- haskell - 99 个 Haskell 问题 #9
- c# - 如何保护应用程序免受 xsrf 攻击并在 asp.net core react js 应用程序中使用 AntiForgeryToken
- powershell - 找不到驱动器。名为“c”的驱动器不存在
- webclient - 在 ParallelFlux 上使用线程睡眠时,它不等待睡眠线程完成并执行 onComplete() 函数
- javascript - 有什么方法可以获取可观察数组的最后 10 个对象
- mongodb - 处理 mongo 上的预定义标签云/标签
- javascript - laravel Livewire 电线:点击不触发功能