パス(URI)を基本的なhttp authによってブロックされないように除外しようとしています。 パスは/ rest(http://example.com/rest)で、cakephp 3アプリケーションのコントローラを表します。これは実際のファイルではなく、rewite-conditionによって書き換えられ、webrootディレクトリのindex.phpによって引き継がれたパスです。http basic authから特定のcakephpコントローラを除外します
ここで書き換えルールがあります:
/var/www/.htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine on
RewriteRule ^$ webroot/ [L]
RewriteRule (.*) webroot/$1 [L]
</IfModule>
/var/www/webroot/.htaccess
:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule^index.php [L]
</IfModule>
私は、Apache 2.4を実行し、異なる構成を試してみましたよ:
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/webroot
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
</Directory>
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
Require expr %{REQUEST_URI} =~ m#/rest/.*#
Require expr %{REQUEST_URI} =~ m#/index.php/rest/.*#
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
... https://stackoverflow.com/a/8979889/1285585
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
</Location>
<Location ~ "/(rest|index.php/rest)">
Satisfy Any
Allow from all
AuthType None
Require all granted
</Location>
から...
https://www.apachelounge.com/viewtopic.php?p=30200
...
<Location "/">
SetEnvIf Request_URI ^/rest noauth=1
SetEnvIf Request_URI /rest noauth=1
SetEnvIf Request_URI ^/index.php/rest noauth=1
SetEnvIf Request_URI /index.php/rest noauth=1
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Order Deny,Allow
Satisfy any
Deny from all
Require valid-user
Allow from env=noauth
</Location>
から... https://serverfault.com/a/475845/229877
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/webroot
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
</Directory>
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
</Location>
<Location "/rest">
Require all granted
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</Virtualhost>
から... https://stackoverflow.com/a/33655232/1285585
<VirtualHost *:80>
ServerAdmin [email protected]
DocumentRoot /var/www/webroot
<Directory /var/www>
Options FollowSymLinks
AllowOverride All
</Directory>
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
</Location>
<Location "/rest">
Allow from all
Satisfy any
</Location>
ErrorLog ${APACHE_LOG_DIR}/error.log
CustomLog ${APACHE_LOG_DIR}/access.log combined
</VirtualHost>
から適応
... HTTP Basic Auth Exclude Single File
から... https://stackoverflow.com/a/13296294/1285585
<Location "/">
AuthType Basic
AuthName "Keawe Development"
AuthUserFile /host/.htpasswd
Require valid-user
</Location>
<Files "index.php/rest">
Satisfy Any
Allow from all
</Files>
<Files "rest">
Satisfy Any
Allow from all
</Files>
からしかし、それらのどれも動作するようには思えません。私はいつもブラウザーからのwgetかauth要求を使ってエラー401を得る。
問題は、パス/レストが条件をパスした後、基本認証の制御下にあるindex.phpに書き換えられていることです。
手がかりはありますか?
'REDIRECT_noauth'は何を意味するのでしょうか? – Shoan
リダイレクトが発生した場合、SetEnvIfルールはリダイレクトの前後に1回と1回適用されます。 Request_URIがリダイレクトの前にマッチした場合、REDIRECT_noautが設定されている間に、リダイレクト後にRequest_URIが与えられたトークン '^/rest /'と一致する場合、noauth環境変数が設定されます。 –