allow authentication for a specific controller in codeigniter using .htaccess

时间:2016-03-02 10:56:36

标签: php apache .htaccess codeigniter .htpasswd

I have added .htaccess authentication for my website and its working fine on browser. But my app using API controller from same website. So i want exclude the authentication for 2 controllers. I tried many codes but didn't worked. Either it authenticates website as well as app controllers, or nothing to both.

Here is my code in .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

Please help to sort out my issue.

By the way i have other code too in same .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

1 个答案:

答案 0 :(得分:1)

您可以使用以下代码删除uris的密码保护:

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