.htaccess重定向除了几个网址之外的所有网址

时间:2014-08-25 17:30:04

标签: apache .htaccess redirect iframe

所以,基本上,我有以下.htaccess

  RewriteEngine On
  RewriteBase /  

  RewriteCond %{REQUEST_URI} !^/online$
  RewriteRule (.*)$ https://secure.example.com/$1 [R=301,L]

但它不起作用:

(http)example.com/online被重定向到(https)secure.example.com

我想要的是:

(http)example.com - > (https)secure.example.com

(http)example.com/foo/ - > (https)secure.example.com/foo /

(http)example.com/online/ - > (http)example.com/online/(无重定向)

那是因为在example.com/online上我有一个iframe,src不在HTTPS上。 另一种方法是以某种方式强制浏览器在页面上显示非https数据(现在我有一个空页面,因为iframe被浏览器阻止)

1 个答案:

答案 0 :(得分:0)

您可以在htaccess(在根文件夹中)中替换当前代码

RewriteEngine On

RewriteCond %{HTTPS} off [OR]
RewriteCond %{HTTP_HOST} !^secure\. [NC]
RewriteCond %{REQUEST_URI} !^/online [NC]
RewriteRule ^(.*)$ https://secure.example.com/$1 [R=301,L]

RewriteCond %{HTTPS} on [OR]
RewriteCond %{HTTP_HOST} ^secure\. [NC]
RewriteRule ^online(/.*)?$ http://example.com/online$1 [R=301,L]

第一条规则重定向到https://secure等值,如果它是http 域名不以secure开头 AND 网址是不是/online/(A OR B) AND C)。

第二条规则将online/重定向到http://example.com/online/,如果它是https或域名以secure开头

相关问题