htaccess:为特定网址打开和关闭https?

时间:2013-03-25 11:29:30

标签: .htaccess mod-rewrite https expressionengine

我正在尝试配置一些条件重定向,我想要的是:

http://www.example.com/login
http://www.example.com/login/*
http://www.example.com/login/account
http://www.example.com/login/account/*
https://www.example.com/account
https://www.example.com/account/*

我的问题是当前.htaccess规则强制/login/account在https下运行,所以我明白了:

http://www.example.com/login
http://www.example.com/login/*
https://www.example.com/login/account
https://www.example.com/login/account/*
https://www.example.com/account
https://www.example.com/account/*

这是现行规则:

<Files .htaccess>
 order allow,deny
 deny from all
</Files>

<IfModule mod_rewrite.c> 
RewriteEngine On 

RewriteCond %{SERVER_PORT} 80
RewriteRule ^(.*)$ - [E=site_url:http://www.example.com]
RewriteCond %{SERVER_PORT} 443
RewriteRule ^(.*)$ - [E=site_url:https://www.example.com]

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /account
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(/account) 
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]

我想问题出在RewriteCond %{REQUEST_URI} !(/account)规则上。我尝试过各种各样的变化,并在各处搜索,但没有发现任何符合我想做的事情。

所以只是为了澄清/account以下的内容必须是https,其他一切都应该是http。

对于info,这是一个表达式引擎站点,因此这些不是物理文件或目录,而是动态生成的URL。

非常感谢任何帮助。

1 个答案:

答案 0 :(得分:1)

试试这个......

RewriteCond %{SERVER_PORT} 80
RewriteCond %{REQUEST_URI} /account
RewriteCond %{REQUEST_URI} !(login/account)
RewriteRule ^(.*)$ https://www.example.com/$1 [R,L]

RewriteCond %{SERVER_PORT} 443
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !(/account) 
RewriteCond %{REQUEST_URI} (login/account)
RewriteRule ^(.*)$ http://www.example.com/$1 [R,L]

ExpressionEngine HTTPS / HTTP的具体示例: https://expressionengine.stackexchange.com/questions/7601/adding-a-htaccess-redirect-to-https-that-plays-nicely-with-existing-ee-htacces/7659#7659