【问题标题】:codeigniter ion auth https redirect infinity loopcodeigniter ion auth https 重定向无限循环
【发布时间】:2012-11-15 09:05:43
【问题描述】:

我在尝试通过 https 访问页面时遇到问题。 我正在使用 Codeigniter 和 Ion Auth

这是我的配置:

$config['base_url'] = "http".((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "s" : "")."://".$_SERVER['HTTP_HOST'].str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

这是我的 .htaccess 文件

<IfModule mod_rewrite.c>
RewriteEngine on
Options +FollowSymLinks
RewriteBase /

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1

RewriteCond %{HTTPS} off
RewriteCond %{REQUEST_URI} (auth|login|pages)
RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]

RewriteCond %{HTTPS} on
RewriteCond %{REQUEST_URI} !(css|images|js|style)
RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]
</IfModule>

<IfModule !mod_rewrite.c>
ErrorDocument 404 /index.php
</IfModule> 

错误 310 (net::ERR_TOO_MANY_REDIRECTS):重定向过多。

位于 https://subdomain.domain.tld/auth/login 的网页导致了过多的重定向。

【问题讨论】:

    标签: codeigniter redirect ssl https ion-auth


    【解决方案1】:

    如果用户通过重定向回 https 的 https 访问,您将重定向到非 SSL 页面:

    RewriteCond %{HTTPS} off
    RewriteCond %{REQUEST_URI} (auth|login|pages)
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]
    

    这会将用户发送到https(这将触发下面的 Cond)

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !(css|images|js|style)
    RewriteRule ^(.*)$ http://%{SERVER_NAME}%{REQUEST_URI} [R=301]
    

    这会将用户 返回 重定向到 http,这会将其无限重定向回此处

    试试这个%{HTTPS} on 条件:

    RewriteCond %{HTTPS} on
    RewriteCond %{REQUEST_URI} !(css|images|js|style)
    RewriteRule ^(.*)$ https://%{SERVER_NAME}%{REQUEST_URI} [R=301]
    

    (注意RewriteRule中的https)

    【讨论】:

    • 我试过了,但我仍然遇到同样的错误:重定向到很多!!
    • 其他页面是否也会发生这种情况,或者只是身份验证/登录页面?
    猜你喜欢
    • 1970-01-01
    • 2015-04-13
    • 2011-12-05
    • 2017-11-13
    • 2013-02-11
    • 1970-01-01
    • 2014-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多