Urls Do Not Work Correctly When Site Is Redirected To Subfolder

I have created Yii site and all URLs worked correctly

I was accessing site like this:


and all URLs worked like these




I am planing to manage multiple versions of sites via htaccess and to have subsites like these



so I’ve moved different versions of sites to these folders and now I can access them like this:



This part worked well so far, and now I’ve changed my htaccess in root folder of my site to something like this:

Options +FollowSymLinks

RewriteEngine on

RewriteCond %{REQUEST_URI} !(.*)versions/1.0

RewriteRule ^(.*)$ versions/1.0/$1 [L]

If I change version from 1.0 to 1.0 I am able to see subsite like my root site:


The problem is, that this works only for default index action of my controller. If I choose to navigate to any other controller using: www.company.com/contact or www.company.com/about, I will see correct URI in address bar, but index controller is always called. I’m not sure how to fix this. Do you have any ideas or alternative solutions for this problem? Thanks!


Did you change the urlmanager setting inside config(folder)->main.php

Please make change there… i hope it will work. Be sure that… you changed both the directory main.php files


chandran nepolean

OK, I have attached demo project 4767

, so it might be easier to debug this issue that way

To start, please change Yii paths in versions/1.0/index.php and versions/2.0/index.php and you are good to go.

There are two sites:

versions/1.0 (blue background) and 

versions/2.0 (green background)

In the root folder there is only a htaccess file in which we can change the version of the site to 1.0 or 2.0.

So, if we set it to 1.0 and access to


it will open index page of versions/1.0 site (the same as localhost/subtest/versions/1.0/)

if we choose


it will call index action again, instead of login action

but if we access sub-site directly like:


everything works fine. how?

I was trying to compare httpRequests from both calls using


in this case


path info is "contact" but in this case:


pathInfo is empty ""

Is there any way to intercept httpRequests and to set this manualy? I’ve tried setting path info beforeAction, but it does not work.


Please change this according version url in both folder

Dont change .htaccess file











Instead of creating subfolder

localhost/subtest/versions/1.0/contact (version).

create two main folder as versions1.0 and versions2.0 like




chandran nepolean

Thanks chandran.

You are right about that, but I want actually to have only one site accessible by:


and to keep all versions of that site under sub folders "/versions/"

I want to change only version number in htaccess in order to have published the version I want. This approach could be very good, because user will always access the same URL "localhost/subtest" and I will be able to easily switch between versions of my site, or to upgrade my site to new version, only by changing version number in root htaccess file.

I’ve figure it out, finally! The solution was fixing htaccess file.

So, if you want to install Yii sites in sub directories, and to show the one by your wish in root directory, this is the magic code that you need to put in your root htaccess file

RewriteEngine on

RewriteCond %{REQUEST_FILENAME} !-f

RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*) versions/2.0/index.php/$1 [QSA,L]

where you can change "versions/2.0/" to your sub directory