• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
CodeIgniter and htaccess - Protect a specific controller and its methods via AuthType?

#1
[eluser]k00k[/eluser]
I asked this on stackoverflow but didn't get any response.

I have an admin controller which has some methods that I want to protect.

http://blabla.com/admin/

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.

Code:
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?

Just to be thorough: I know how to use htaccess and htpasswd. My question is how to protect a controller which is not really a directory. I tried using the Location directive with no success.

#2
[eluser]k00k[/eluser]
I got this to work by following this post:

http://ellislab.com/forums/viewthread/141775/

#3
[eluser]monaye[/eluser]
How did you handle on url?

if default rout is to show "welcome"

http://myapplication.com/ => "welcome"

http://myapplication.com/admin/ => "welcome"

#4
[eluser]k00k[/eluser]
[quote author="monaye" date="1302076760"]How did you handle on url?

if default rout is to show "welcome"

http://myapplication.com/ => "welcome"

http://myapplication.com/admin/ => "welcome"[/quote]

I'm not sure what you're asking, please try to be a bit more descriptive in your question.

My default route is to a controller called 'home':

$route['default_controller'] = "home";

However, this has no effect on the fact that I can visit http://myapplication.com/admin/ and be prompted by htaccess for password. Like I said, I just followed that other post (creating real folder named 'admin', copying the CI index.php and setting up .htaccess/.htpasswd) and it worked fine.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.