1

mod_rewrite を使用して /controller を /index.php?controller=%controller% にリダイレクトする htaccess ファイルがあります。

このような:

# Various rewrite rules.
<IfModule mod_rewrite.c>
  RewriteEngine on

  # Rewrite current-style URLs of the form 'index.php?controller=x&action=y'.
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php?controller=$1 [L,QSA]
</IfModule>

今、私ができるようにする必要があるのは、コントローラーの 1 つを HTTP 認証で動作させることです。これが最善の方法かどうかを尋ねているのではなく、単にどうすればよいかを尋ねているだけです。

例:

http://www.example.com/ - It requires no auth
http://www.example.com/secret - requires auth
4

2 に答える 2

4
<Location /secret>
  AuthName localhost
  AuthType Basic
  AuthUserFile <file>
  Require valid-user
</Location>
于 2008-11-11T22:39:41.817 に答える
1

私はそれを行うためにPHPを使用することになりました:

if (in_array($controllerString, $configuration['protected']))
{
    $authenticated = false;
    if (!isset($_SERVER['PHP_AUTH_USER'])) {
        header('WWW-Authenticate: Basic realm="My Realm"');
        header('HTTP/1.0 401 Unauthorized');
        echo 'You are unatuhorized to access this section of the website.';
    } else if ($_SERVER['PHP_AUTH_USER'] == 'admin' && $_SERVER['PHP_AUTH_PW'] == 'admin'){
        $authenticated = true;
    }

    if (!$authenticated)
    {
        unset($_SERVER['PHP_AUTH_USER']);
        die();
    }
} 
于 2008-11-11T22:30:32.600 に答える