如何将所有重定向到ssl和index.php但不是ssl,但重定向到特定页面上的index.php

问题描述:

我希望所有人都强制重定向到https,但不在特定页面上当前我有这个.htaccess文件:如何将所有重定向到ssl和index.php但不是ssl,但重定向到特定页面上的index.php

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

我希望所有重定向到HTTPS,但强制HTTP特定页面上: /exchage

什么代码,我需要把我的.htaccess文件来实现这个功能?谢谢。

如何向HTTPS重定向添加另一个条件以检查路径是否不以exchange开头? (我假设你拼错可置换岁)

RewriteEngine on 
RewriteCond %{REQUEST_URI} !^/exchange 
RewriteCond %{HTTPS} off 
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_URI} ^/exchange 
RewriteCond %{HTTPS} on 
RewriteRule ^(.*)$ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

一旦你更新你的.htaccess文件,请重新启动浏览器。否则,如果之前看到URL使用https,它可能会强制https。

+0

交换页面仍然转到https。 :( –

+0

我刚刚更新了..你能再试一次吗? –

+0

我试了一遍,但问题仍然存在:( –

我用这段代码解决了这个问题。

RewriteEngine on 
RewriteCond %{HTTPS} off 
RewriteCond %{THE_REQUEST} !/exchange 
RewriteRule^https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{HTTPS} on 
RewriteCond %{THE_REQUEST} /exchange 
RewriteRule^http://%{HTTP_HOST}%{REQUEST_URI} [L,R=301] 
RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule ^(.*)$ /index.php?path=$1 [NC,L,QSA] 

花了我近3个小时才出来这段代码。

+0

很酷,这适用于你。只需注意:这将触发http/https规则,如果URL _contains_'/ exchange' ...例如'/ anything/exchange/whatever /'也将被强制为http。 –

+0

我更新它不会触发该问题。 –