
Eu tenho uma instância do Linux hospedando um site WordPress e tem autenticação HTTP básica habilitada para todo o site. Agora quero desabilitar a autenticação HTTP básica para um caminho específico que podemos chamar /auth-free-url-2019
.
Meu primeiro pensamento foi definir uma variável ENV no .htaccess
arquivo da seguinte forma:
SetEnvIf REQUEST_URI "^/auth-free-url-2019" allowed_page=1
e então adicionar o seguinte em minha autenticação
AuthUserFile SOME_AUTH_FILE
AuthName "AUTH NAME"
AuthType Basic
Order deny,allow
Deny from all
Satisfy Any
Require valid-user
Allow from all
Isso não funcionou e eu li sobre algo sobre mod_rewrite possivelmente conflitando com as variáveis de ambiente, então decidi tentar algo mais simples adicionando uma <If>
diretiva ao meu arquivo .htaccess da seguinte maneira:
<If "%{REQUEST_URI} =~ m#auth-free-url-2019#i">
Order allow,deny
Satisfy Any
Allow from all
Deny from none
</If>
<Else>
Header set Checked-Request-url %{REQUEST_URI}e
AuthUserFile SOME_AUTH_FILE
AuthName "AUTH NAME"
AuthType Basic
Order deny,allow
Deny from all
Satisfy Any
Require valid-user
</Else>
Isso também não está funcionando e adicionei um Header set
para visualizar o valor de REQUEST_URI
e parece estar correto.
Na <If>
diretiva eu tentei
"%{REQUEST_URI} =~ m#auth-free-url-2019#i"
"%{REQUEST_URI} =~ /\/auth-free-url-2019$/i"
"%{REQUEST_URI} =~ /.*auth-free-url-2019.*/i"
"%{REQUEST_URI} == '/auth-free-url-2019'"
"%{REQUEST_URI} == 'auth-free-url-2019'"
"%{REQUEST_URI} == 'auth-free-url-2019'"
"-n %{REQUEST_URI}"
e apenas o último desligará a autenticação básica. Não tenho certeza de qual é o problema, mas por algum motivo, minhas tentativas de comparação com o valor REQUEST_URI não estão funcionando. Eu tentei o mesmo <If>
bloco de diretiva, mas para HOST_NAME e parece funcionar, então tem algo a ver com REQUEST_URI.
Qualquer ajuda seria apreciada.
Apache2.4.37
RHEL
e aqui está meu arquivo .htaccess
# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
<If "%{REQUEST_URI} =~ m#auth-free-url-2019#i">
Order allow,deny
Satisfy Any
Allow from all
Deny from none
</If>
<Else>
AuthUserFile SOME_AUTH_FILE
AuthName "AUTH NAME"
AuthType Basic
Order deny,allow
Deny from all
Satisfy Any
Require valid-user
#Allow from all
</Else>
# Exclude the WP CRON and other scripts from authentication
<FilesMatch "(wp-cron.php|another-script.php)$">
Satisfy Any
Order allow,deny
Allow from all
Deny from none
</FilesMatch>
# BEGIN W3TC Page Cache core
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTPS} =on
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{SERVER_PORT} =443
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{HTTP:X-Forwarded-Proto} =https [NC]
RewriteRule .* - [E=W3TC_SSL:_ssl]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteRule .* - [E=W3TC_ENC:_gzip]
RewriteCond %{HTTP_COOKIE} w3tc_preview [NC]
RewriteRule .* - [E=W3TC_PREVIEW:_preview]
RewriteCond %{REQUEST_METHOD} !=POST
RewriteCond %{QUERY_STRING} =""
RewriteCond %{HTTP_COOKIE} !(comment_author|wp\-postpass|w3tc_logged_out|wordpress_logged_in|wptouch_switch_toggle) [NC]
RewriteCond "%{DOCUMENT_ROOT}/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" -f
RewriteRule .* "/wp-content/cache/page_enhanced/%{HTTP_HOST}/%{REQUEST_URI}/_index%{ENV:W3TC_SSL}%{ENV:W3TC_PREVIEW}.html%{ENV:W3TC_ENC}" [L]
</IfModule>