【问题标题】:htaccess: turning https on and off for specific urls?htaccess:打开和关闭特定网址的 https?
【发布时间】:2013-03-25 11:29:30
【问题描述】:

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

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。

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

任何帮助将不胜感激。

【问题讨论】:

    标签: .htaccess mod-rewrite https expressionengine


    【解决方案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

    【讨论】:

    • 谢谢你,但没有运气,仍然得到相同的结果。谢谢你的链接,我看看能不能弄明白。
    • 经过多次调整,我终于到了那里,对你的建议做了一点小小的修改。所有RewriteCond 语句都需要包含/account?.*,但这只是特定于我的特定站点。谢谢
    猜你喜欢
    • 2018-11-13
    • 1970-01-01
    • 2018-11-02
    • 1970-01-01
    • 2013-10-08
    • 1970-01-01
    • 1970-01-01
    • 2012-11-19
    • 1970-01-01
    相关资源
    最近更新 更多