【问题标题】:How can I configure htaccess for https-rewriting?如何为 https 重写配置 htaccess?
【发布时间】:2013-11-21 18:54:51
【问题描述】:

我将 https:// 用于某些子目录(/login、/admininstration),为此我找到了一些示例 - 但另一方面,我必须确保所有其他页面都重定向到 http://。

现在,我通过链接将用户发送到 https://,但是当他们离开登录区域时,他们仍处于 https:// 模式。

我现在在标准配置中使用 RewriteCond:

SetEnv APPLICATION_ENVIRONMENT show
RewriteEngine On

RewriteBase /
RewriteCond %{HTTP_HOST} !^www.xxxseitexxx.de$ [NC]
RewriteRule ^(.*)$ http://www.xxxseitexxx.de/$1 [L,R=301]
RewriteCond %{REQUEST_FILENAME} -s [OR]
RewriteCond %{REQUEST_FILENAME} -l [OR]
RewriteCond %{REQUEST_FILENAME} -d

RewriteRule ^.*$ - [NC,L]
RewriteRule ^.*$ /index.php [NC,L]

RewriteRule !\.(js|ico|gif|jpg|jpeg|png|css|inc|pdf|csv|zip|rm|mp3|swf)$ index.php

提前致谢!

【问题讨论】:

    标签: .htaccess https rewrite


    【解决方案1】:

    您可以在其他规则之上使用此规则:

    # force HTTP for not login or admininstration
    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !/admininstration|login/ [NC]
    RewriteRule ^ http://%{HTTP_HOST}%{REQUEST_URI} [L,R=302]
    
    # force HTTPS for login or admininstration
    RewriteCond %{HTTPS} off
    RewriteRule ^(admininstration|login)/ https://%{HTTP_HOST}%{REQUEST_URI} [L,NC,R=302]
    

    【讨论】:

    • 谢谢,但很抱歉 - 它不起作用。 http-Part 运行良好,如果您现在使用 https 调用页面,您将获得 http-Version。但是 https 部分不起作用:登录进入 http 页面(即使我调用 https)并且管理导致开始页面。我应该提一下,我们调用 /administration/start,而不仅仅是 /administration(但它应该适用于 /administration 下的任何东西),并且整个事情都是作为虚拟路径生成的,由框架生成。
    • 如果您使用的是框架,那么可能已经存在一些规则。你能在你的问题中发布你当前的 .htaccess 吗?
    • 您在上面看到的是我的完整 htaccess。也许 RewriteRule 有冲突 ^(.*)$ xxxseitexxx.de/$1
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-07-23
    • 1970-01-01
    • 2016-11-10
    • 2014-07-18
    • 1970-01-01
    相关资源
    最近更新 更多