Phanix

Just writing

Exclude a url path using apache .htaccess

用 http auth 時,如果要避開某些 url 不做檢查(例如API)。

一般來說全部都要檢查的話,.htaccess 檔案會長這樣。

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/opt/www/restrictsite/.htpasswd
Require valid-user

 

但是如果某些URL不做檢查,則可以用 SetEnvIf Request_URI 來exclude

AuthType Basic
AuthName "Restricted Content"
AuthUserFile /var/opt/www/api_v2/.htpasswd
SetEnvIf Request_URI "/verify" noauth=1
<RequireAny>
	Require env noauth
	Require env REDIRECT_noauth
	Require valid-user
</RequireAny>

Original link: Phanix's Blog

Like my work??
Don't forget to support or like, so I know you are with me..

CC BY-NC-ND 2.0

Want to read more ?

Login with one click and join the most diverse creator community.