CodeIgniter和htaccess - 通过AuthType保护特定的控制器及其方法? [英] CodeIgniter and htaccess - Protect a specific controller and its methods via AuthType?
问题描述
我有一个管理控制器,有一些我想要保护的方法。
http://blabla.com/ admin / edit_coupon /
http: //blabla.com/admin/edit_photo/
我不需要为这个网站建立完整的身份验证系统,因此我只想对任何/ admin / URL使用htaccess和AuthType。
我当前的.htaccess是一个基本的CI。
RewriteEngine on
RewriteRule ^ $ /index.php [L]
RewriteCond $ 1!^(index\.php | uploads | images | css | js | videos | code | robots \.txt | favic
on\.ico)
RewriteRule ^(。*)$ /index.php/$1 [L]
我如何做?
[Added]
我知道使用htaccess和htpasswd。我的问题是如何保护不是真正的目录(/ admin)的CI控制器。我试着使用Location指令没有成功。这是htaccess:< Location / admin>
AuthUserFile /var/www/vhosts/blabla.com/httpdocs/.htpasswd
AuthType Basic
AuthNameAdmin
需要有效的用户
< / Location> ;
RewriteEngine on
RewriteRule ^ $ /index.php [L]
RewriteCond $ 1!^(index\.php | uploads | images | css | js | videos | code | robots\.txt | favicon\.ico)
RewriteRule ^(。*)$ /index.php/$1 [L]
这会抛出500个服务器错误。
我相信Location指令不能在htaccess文件中,所以我也尝试了这个服务器的httpd.conf里面这个VirtualHost。
解决方案我得到这个工作遵循的意见在此帖子中:
http:// ellislab.com/forums/viewthread/141775/
I have an admin controller which has some methods that I want to protect.
http://blabla.com/admin/edit_coupon/
http://blabla.com/admin/edit_photo/
I don't need a full blown authentication system for this site, so I'd prefer to just utilize htaccess and AuthType for any /admin/ URLs.
My current .htaccess is a basic CI one.
RewriteEngine on RewriteRule ^$ /index.php [L] RewriteCond $1 !^(index\.php|uploads|images|css|js|videos|code|robots\.txt|favic on\.ico) RewriteRule ^(.*)$ /index.php/$1 [L]
How do I do this?
[Added] I know how to use htaccess and htpasswd. My question is how to protect a CI controller which is not really a directory (/admin). I tried using the Location directive with no success. Here is that htaccess:
<Location /admin> AuthUserFile /var/www/vhosts/blabla.com/httpdocs/.htpasswd AuthType Basic AuthName "Admin" Require valid-user </Location> RewriteEngine on RewriteRule ^$ /index.php [L] RewriteCond $1 !^(index\.php|uploads|images|css|js|videos|code|robots\.txt|favicon\.ico) RewriteRule ^(.*)$ /index.php/$1 [L]
That throws a 500 Server Error.
I believe the Location directive can't be in an htaccess file, so I also tried it inside this server's httpd.conf for this VirtualHost. Doesn't throw an error that way, but doesn't work either.
解决方案I got this to work by following the advice in this post:
http://ellislab.com/forums/viewthread/141775/
这篇关于CodeIgniter和htaccess - 通过AuthType保护特定的控制器及其方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!