Configure application for front-end and back-end

I read this tutorial:

But I’m not sure if this is precisely what I’m after.

Basically what I want is for the front-end + all links to be configured as such:








How can I acheive this? Just after a basic idea on how to do it.

After setting url type to path in both configs, you have to add a line to your .htaccess:

RewriteRule ^admin backend.php

Also set urlSuffix to ‘.php’. Hope, this will work.

I was hoping there would be a way of doing this without needing another entry script?

see here

I have no idea how to create module, is there a guide somewhere?

yiic shell ../index.php

>>module backend

in config/main.php

 'modules' => array('backend'),

>>model post

>> crud Post backend/Post


I think that using of two entry scripts makes things more clear. Because otherwise you’ll have to play with GET params and add some logic to index.php (e.g. which config to choose).

Anyways, try this:

RewriteRule ^admin index.php?admin

About admin module… My humble opinion is: the backend part is a self-sufficient application and it shouldn’t be a module of the frontend. Both parts have different configs, controllers, views, but share models.

But I think an admin module is a good idea too, at least, for not large applications.

andy_s - how would I configure all backend url’s to reference backend.php rather than index.php?

Also how do I omit the ‘site’ part of the URL when using CMenu widget? For example I want all URLs to be in the format of

[color="#000080"]/yiiapp/contact[/color] instead of [color="#000080"]yiiapp/site/contact[/color]

I already have [color="#000080"]RewriteRule . index.php[/color], if I add the rule above it does not work.

In your case you’ll need url rules:











Yes, I know that’s not very beautiful. Also, I don’t use url manager in the backend part, because no one cares about beautiful urls there.

Use UrlManager rules again…


Options +FollowSymLinks

IndexIgnore */*

RewriteEngine on

# Make the backend accessible via url: http://site/admin.

RewriteRule ^admin backend.php

# If a directory or a file exists, use it directly.

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

# Otherwise forward it to index.php.

RewriteRule . index.php

When you’ll try to access http://site/admin then backend.php will be executed. Isn’t it?

Yes you’re right - I was putting that rule at the bottom of the htaccess!


Just a slight issue I came across. If I navigate to: /webapp/backend.php

I get a CHttpException: Unable to resolve the request "site/error".

Any idea what might be causing this?

(I came across this issue after trying to log in at /webapp/admin/login)

EDIT: I managed to fix the above error. However it seems that logging in at [color="#000080"]/webapp/admin/login[/color] redirects me to [color="#000080"]/webapp/backend.php[/color] after logging in. Have you got any idea why?

In your backend controllers you should have a controller "SiteController" with action index, just like in the frontend part. It is the main page of your backend.

Seems it is the only case when this happens. If you’ll try to directly go to the login action from the frontend, you’ll be then redirected to backend.php (since nothing is stored in the returnUrl). Try to go to /webapp/admin. Here you will be redirected to login action and after logged in you’ll get back to /webapp/admin.

/webapp/admin just calls actionIndex which renders admin/index.php

Do you mean I should enforce actionIndex to redirect to webapp/admin/login?

I just thought you denied access to all controllers’ actions (except site/login), if a user is not logged in. So if he will try to access site/index, he will be redirected to login page.