How to make backend acessible by routes?

Hello there. I have been looking for an answer to that for a while and could not find anything useful. I am using the Yii advanced template and i have configured my server to access it by //frontend/ and //backend/

But i wish to access backend from //frontend/admin

i am really lost on how to do this. I am using yii2 for a year now and that is one question that i never found an answer, will you guys help me with this? Thanks :)

This needs to happen on the web server, not in Yii. Remember, frontend and backend are two completely separate sites so it does not make sense in normal use to have one site directly mapped to the other, if you want to do that, put all the backend stuff in the frontend!

What you could do is to add a rewrite rule onto your web server so that any request to "frontend/admin" is rewritten to "backend" - they must be on the same server obviously. But this is a hack really. It will probably also cause cookie/login issues unless you hard-code the same domain into both sets of cookies.

Another possibly acceptable and much easier solution is to get a call to frontend/admin to redirect to the other site automatically with a 302 so that the domain changes and all the cookies etc. will work correctly.

You should probably use this template :

That will give you /frontend/backend links.

Hi Lukos, thanks for your answer. You are right, since backend is a separate site. I think the rewrite rule will be the better solution. What about if i wish to add a new tier in my application, called API? Do you have any insights or links that could help me to achieve this? Thanks again for the reply, it was useful. :)

Hey jacmoe, thanks for your answer. I know this template from kartik, but what i really want is to learn it and not just use a practical, do you understand? Because my needing today is related only to 1 backend, but in future, if i need a new tier on my app i wont be able to do it. For a practical example, in this app i want to build an API, separate from backend and frontend.

C ya

Hey, i found one solution in the following link: