php - 将所有 www 或非 www 页面重定向到 https://www,除了一页
问题描述
我试图https://www.
在我的所有页面上强制执行,除了hotels.php
. 我下面的当前代码是添加www.
两次,即https://www.www.example.com
.htaccess
RewriteEngine On
RewriteCond %{HTTPS} =off
RewriteCond %{REQUEST_URI} !^\/hotels.php\/
RewriteRule (.*) https://www.%{HTTP_HOST}/$1 [L,R=301]
RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/hotels.php\/
RewriteRule (.*) http://www.%{HTTP_HOST}/$1 [L,R=301]
让我知道我在这里缺少什么导致问题。谢谢
解决方案
试试这些重写条件:
RewriteEngine On
RewriteCond %{HTTP_HOST} !^www\.
RewriteRule ^ https://www.%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force https:// for all except your desired URLs
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !/hotels.php/ [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
# force http:// for your desired URLs
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} /hotels.php/ [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
推荐阅读
- jquery - 如何使用ajax和CI修复分页链接,单击时不更新
- azure-devops - 我可以使用此工具从 OnPrem 迁移到 Cloud 吗?
- r - 有没有办法让 ggplot 在添加新数据时遵循特定的路线?
- html - 如何编辑 Bootstrap5 [在哪里可以找到 SCSS _grid.scss?]?
- swift - 如何在 Bound 是通用的地方扩展 ClosedRange
- python - PyInstaller:找不到脚本
- amazon-web-services - Pinpoint 使用 .NET API 给出模板错误
- javascript - 使用spring服务器在数组中存储和对象不工作
- python - ConnectionTimeoutError AWS elasticsearch使用Django elasticsearch-dsl
- oauth - OpenIddict 本地验证 - 多个资源服务器的多个加密密钥