Welcome Guest, Not a member yet? Register   Sign In
htaccess for front/backend
#1

[eluser]SpooF[/eluser]
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.

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

[Edit]

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:

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB