3

ログインしているすべてのユーザーに https を強制しようとしています。私のアプリのほとんどは、ユーザーがログインする必要がありますが、ログイン ステータスに応じて、http (ゲスト) と https (ログイン ユーザー) の両方を介して提供する必要があるページと、http のみにする必要があるページがまだたくさんあります。

私は Yii フレームワークを使用しており、ログインしているユーザーのすべてのページに https を強制しようとしています。ユーザーはモジュールを介して制御されます。

ここに私の現在の .htaccess があります

Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.mysite.com/$1 [R=301,L]

#RedirectMatch 301 ^/tk/(.*)$ http://admin.mysite.com/$1
#RewriteRule ([a-z0-9-]+)/? http://$1.mysite.com [R=301,NC,L]

# if a directory or a file exists, use it directly

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# otherwise forward it to index.php

#RewriteRule . index.php
RewriteRule .* index.php [QSA,L]
4

4 に答える 4

1

書き換えルールは適切な解決策ではありません。リソースが多すぎます。

より良い使用:

RedirectPermanent / https://domain.tld

可能であれば、.htaccessファイルではなくApache構成に直接。

于 2013-02-15T23:28:28.463 に答える
1

セッションまたは Cookie を使用する場合は、セッションを確認する必要があります。セッションが有効である場合は、ユーザーを https サイトにリダイレクトします。

これは PHP で行う必要があります。純粋な .htaccess でこれを行う方法はありません。

于 2013-02-15T21:08:34.987 に答える
0

セッションの名前が付けられた Cookie を使用する場合sessionは、RewriteCond を使用してセッション Cookie をテストできます。

RewriteCond %{HTTP_COOKIE} session
RewriteRule .* https://www.mysite.com/$0 [R,L]
于 2013-02-15T23:24:04.933 に答える
0

これはフィルターを使用して行うことができます。

Yii CFilter ドキュメント

フィルタ クラスのサンプル:

class CHttpsCheckFilter extends CFilter {

protected function preFilter($filterChain) {
    //place your checking logic here.
    //$filterChain->controller is yor targer controller
    //other useful methods and fields you can find in official documentation.
    if ( !Yii::app()->getRequest()->isSecureConnection ) {            
        $url = 'https://your-new-path';
        Yii::app()->request->redirect($url);
        return false;
    } else
        return true;
}

protected function postFilter($filterChain) {
    return true;   
}

filters次に、メソッドを実装して、このフィルターをコントローラーにアタッチする必要があります。

public function filters()
{
    return array(
        'accessControl', // perform access control for CRUD operations
        array(
            'CHttpsCheckFilter',
        ),
    );
}

これが基本的な機能です。フィルターに追加のロジックを追加して、追加のルールのカスタム メソッドのターゲット コントローラーをチェックできます...または、すべてのセキュリティ ルールが含まれている場合があります。

于 2013-02-16T17:53:15.737 に答える