将所有内容从http重定向到https(联系页面除外)

问题描述:

如何将网站上的所有页面从https重定向到http,但/ contact页面却始终要重定向到https域?

How do I redirect all pages on a site from https to http except the /contact page which I always want to be redirected to the https domain?

我可以将所有内容从http重定向到https,如下所示:

I can redirect all from http to https as follows:

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

但是,我在为联系人页面添加例外时遇到了麻烦,我想始终将其从http重定向到https

However, I'm having trouble adding the exception for the contact page which I want to always redirect from http to https

更新

我已经按照建议添加了规则,但是/ contact现在重定向到/index.php?q=contact。

I've added the rules as suggested but /contact is now redirecting to /index.php?q=contact.

我正在使用具有以下规则的ModX:

I'm using ModX which has the rules:

# The Friendly URLs part
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]

为什么与将/ contact(http)重定向到/ c的新规则冲突完整(https)?

Why is this conflicting with the new rule to redirect /contact (http) to /contact (https)?

谢谢:)

使用此:

RewriteEngine On

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

RewriteCond %{HTTPS} =on
RewriteCond %{REQUEST_URI} \/contact\/ 
RewriteRule (.*) http://%{HTTP_HOST}/$1 [L,R=301]