静态页面的 Htaccess 条件 https [英] Htaccess conditional https for static pages

查看:39
本文介绍了静态页面的 Htaccess 条件 https的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的网站启用了 HTTPS,并且所有页面都使用仅使用 HTTPS.客户现在需要about-ustermsofus等静态页面显示为HTTP页面而不是HTTPS.这意味着即使用户尝试以 HTTPS 的形式打开 about-us 页面,它也应该重定向到 about-us 的 HTTP 版本.

My site is HTTPS enabled and all the pages are served using HTTPS only. Client now has the requirement where he wants to show static pages like about-us, termsofus as HTTP pages and not as HTTPS. This means that even if the user tries to open about-us page as HTTPS it should redirect to HTTP version of about-us.

我的.htaccess代码如下:

Options -Indexes

<IfModule mod_rewrite.c>

RewriteEngine on
#RewriteCond %{HTTPS} off
#RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} !^\/about-us
RewriteCond %{REQUEST_URI} !^\/termsofus
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} \/about-us [OR]
RewriteCond %{REQUEST_URI} \/termsofus
RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php
</IfModule>

问题: 每当我打开 about-us 页面的 HTTP/HTTPS 版本时,它一直将我重定向到 index.php.例如:https://example.com/about-ushttps://example.com/index.php

Problem: Whenever I open HTTP/HTTPS version of about-us page it keeps on redirecting me to index.php. For example: https://example.com/about-us to https://example.com/index.php

该网站使用 PHP YII 框架.

The site uses PHP YII framework.

推荐答案

使用 THE_REQUEST 变量代替 REQUEST_URI.THE_REQUEST 变量表示 Apache 从您的浏览器收到的原始请求,并且在执行某些重写规则后不会被覆盖.

Use THE_REQUEST variable instead of REQUEST_URI. THE_REQUEST variable represents original request received by Apache from your browser and it doesn't get overwritten after execution of some rewrite rules.

Options -Indexes

RewriteEngine on

RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} !\s/+(about-us|termsofus) [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} \s/+(about-us|termsofus) [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php

确保在测试此更改之前清除浏览器缓存.

Make sure to clear your browser cache before testing this change.

这篇关于静态页面的 Htaccess 条件 https的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆