Moving Yii Project Into A Folder

I have a Yii project deployed on a server into a separate folder. That is it resides in the webroot/projectfolder. All setup is done and project works ok when accessed via URL http://server.domain/projectfolder. What I want to do next is to make the project accessible from http://server.domain without moving the entire project. I thought, it is enough to edit relative paths in the Yii’s index.php file and move the file one level up from projectfolder. Unfortunately, after doing so, I encountered a problem with different assets. Home page shows up without css-style applied, because css-files can not be found. The project searches them in webroot/css instead of webroot/projectfolder/css. Also it tries to access non-existing webroot/assets folder (whereas it remains in webroot/projectfolder/assets).

So, the question is how to change Yii’s project config for this environment: index.php is in the webroot, and the rest of the project is in a subfolder.

P.S. I found the related article here. But it describes a bit more complicated case than I want. I’d like to adjust all the stuff in more simple way, if possible.

Thanks in advance.


why didn’t use header on root index.php file like that?

header("Location: http://server.domain/projectfolder");

Apparently, this does not change the project URL - all its stuff will still be accessible in the same way as at the moment, that’s from inside the folder.

Maybe I didn’t understand what you want to do,

do you want to all assets and css path on the root ?

Try something like that in your config:


   //assets, see


      // change the path on disk


      // change the url





Actually, no. I want to leave the project (including assets and css) ‘as is’ in its subfolder, but does bootstrap it from webroot. If I understand correctly, we define in .htaccess that all requests which are not files and directories are passed to index.php, and then it should pick up Yii core, controllers, views, resources, etc based on the given configuration. It works when index.php resides in the subfolder, but it breaks when the index.php moved outside the subfolder and path for config is changed accordingly:


It looks like I should possibly add something to the config itself. ‘basePath’ should not change, because config/main.php is still in the same relative position to the ‘protected’ folder as usual. I’m not sure if BaseURL could help.

Then why not try it? baseUrl form AssetMannager applies only to assets folder so ‘protected’ basePath from index will not change.

So, you want all the project intact in this folder.

The only you want is to run the website also from the root




will be run the same project so

add an extra index.php on the root containing