将https重定向到除登录页面之外的http

时间:2016-12-07 06:45:10

标签: php regex .htaccess redirect drupal-7

我需要将我的网站的所有网页从https重定向到httpsign-in页面。我想如果有人尝试通过sign-in浏览http页面,则应将其重定向到https。我的网站是在drupal 7下开发的。但是,我在.htaccess写了一些条件,但没有运气。我做了什么:

RewriteEngine On
RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !^/sign-in
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

通过上面的代码,所有网页都将https重定向到http,但没有获得sign-in的例外。

2 个答案:

答案 0 :(得分:1)

将这两个重定向规则放在.htaccess的顶部:

RewriteEngine On

# redirect anything except /sign-in to http
RewriteCond %{HTTPS} on
RewriteCond %{THE_REQUEST} !/sign-in [NC]
RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

# redirect /sign-in to https
RewriteCond %{HTTPS} off
RewriteCond %{THE_REQUEST} /sign-in [NC]
RewriteRule ^ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301,NE]

答案 1 :(得分:0)

尝试类似这样的事情

<link rel="import" href="../bower_components/polymer/polymer.html">
<link rel="import" href="shared-styles.html">

<link rel="import" href="../bower_components/iron-icon/iron-icon.html">

<link rel="import" href="../bower_components/polymerfire/firebase-app.html">
<link rel="import" href="../bower_components/polymerfire/firebase-query.html">
<link rel="import" href="pick-me-up-skill-card.html">