允许使用 .htaccess 对 Codeigniter 中的特定控制器进行身份验证


allow authentication for a specific controller in codeigniter using .htaccess

我已经为我的网站添加了.htaccess身份验证,它在浏览器上运行良好。但是我的应用程序使用来自同一网站的 API 控制器。所以我想排除 2 个控制器的身份验证。我尝试了很多代码,但没有奏效。它要么对网站和应用程序控制器进行身份验证,要么对两者都不进行身份验证。

这是我在 .htaccess 中的代码 -

SetEnvIfNoCase Request_URI "/mycustomer/.*" app_customer_uri
SetEnvIfNoCase Request_URI "/myvendor/.*" app_vendor_uri
Order Deny,Allow
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/new_html/.htpasswd
Require valid-user
Deny from all
Allow from env=app_customer_uri
Allow from env=app_vendor_uri
Satisfy any

请帮助解决我的问题。

顺便说一句,我在同一个 .htaccess 中也有其他代码 -

RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?/$1 [L]
Redirect 301 /Mag/ http://myvender.com/mag/
Redirect 301 http://myvender.com/services/search/cleaning-service http://myvender.com/en/services/search/cleaning-service

# 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>
# END WordPress

## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive on
    ExpiresByType images/jpg "access plus 6 month"
    ExpiresByType images/jpeg "access plus 6 month"
    ExpiresByType images/gif "access plus 6 month"
    ExpiresByType images/png "access plus 6 month"
</IfModule>
## EXPIRES CACHING ##
Options -Indexes

您可以使用以下代码删除两个 uri 的密码保护:

SetEnvIfNoCase Request_URI /(mycustomer|myvender)/.*$ allowed_uris=1
#Auth    
AuthName "Restricted Area"
AuthType Basic
AuthUserFile /var/www/new_html/.htpasswd
Require valid-user   
 #Here is where we allow/deny
Order Deny,Allow
Satisfy any
Deny from all
Require user AuthorizedUser
Allow from env=allowed_uris