• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
htaccess for front/backend

For the website that I'm currently working on I'm using a single controller and a single function (doing my own remapping), probably fairly stupid, but its the best thing I could think of. The problem comes when I want to run a administrative backend on the site. my current htaccess has a rewrite rule of ^(.*)$ /index.php/main/index/$i [L]. However when someone types http://domain.com/admin it will use a different rule. ^(.*)$ /index.php/admin/home$i [L] where admin is a directory inside of my controllers.

I would expect that at the top of my htaccess file I could do something like this.

RewriteCond $1 ^(admin)
RewriteRule ^(.*)$ /index.php/admin/$1 [L]

Then have my other rewrite conditions for ^(.*)$ /index.php/main/index/$i [L] below it. However this didnt work. Now there may be an even better way to get around this just by using some functionality that CI has. I've never really used multi controllers. For most of my sites I stick to a single controller.


After writing this post and looking back at the code I found out what I did wrong.

The rewrite rule shouldn't have the admin in it. It should look like this:

RewriteCond $1 ^(admin)
RewriteRule ^(.*)$ /index.php/$1 [L]

[eluser]louis w[/eluser]
You could shorten that to be on one line like this:

RewriteRule ^/admin/?$ /index.php/admin [NC,L]

- You do not need the Cond if you are just testing for a directory name
- I always like adding a NC to it to make it not case sensitive

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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