argonius
(Gogyinsomnia)
October 9, 2013, 11:57am
1
I have created Yii site and all URLs worked correctly
I was accessing site like this:
www.company.com/templates/
and all URLs worked like these
www.company.com/home
www.company.com/contact
www.company.com/about
I am planing to manage multiple versions of sites via htaccess and to have subsites like these
www.company.com/versions/1.0/
www.company.com/versions/1.1/
so I’ve moved different versions of sites to these folders and now I can access them like this:
www.company.com/versions/1.0/home
www.company.com/versions/1.0/contact
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:
www.company.com/home
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!
argonius:
I have created Yii site and all URLs worked correctly
I was accessing site like this:
www.company.com/templates/
and all URLs worked like these
www.company.com/home
www.company.com/contact
www.company.com/about
I am planing to manage multiple versions of sites via htaccess and to have subsites like these
www.company.com/versions/1.0/
www.company.com/versions/1.1/
so I’ve moved different versions of sites to these folders and now I can access them like this:
www.company.com/versions/1.0/home
www.company.com/versions/1.0/contact
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:
www.company.com/home
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!
Hi,
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
Thanks,
chandran nepolean
argonius
(Gogyinsomnia)
October 9, 2013, 6:31pm
3
OK, I have attached demo project 4767
subtest.zip
, 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
localhost/subtest
it will open index page of versions/1.0 site (the same as localhost/subtest/versions/1.0/)
if we choose
localhost/subtest/login
it will call index action again, instead of login action
but if we access sub-site directly like:
localhost/subtest/versions/1.0/login
everything works fine. how?
argonius
(Gogyinsomnia)
October 10, 2013, 10:25am
4
I was trying to compare httpRequests from both calls using
Yii::app()->getRequest()->getPathInfo()
in this case
localhost/subtest/versions/1.0/contact
path info is "contact" but in this case:
localhost/subtest/contact
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.
argonius:
I was trying to compare httpRequests from both calls using
Yii::app()->getRequest()->getPathInfo()
in this case
localhost/subtest/versions/1.0/contact
path info is "contact" but in this case:
localhost/subtest/contact
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.
Hi,
Please change this according version url in both folder
Dont change .htaccess file
‘rules’=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'login'=>'site/login',
'index'=>'site/index',
'about'=>'site/about',
'contact'=>'site/contact',
'home'=>'site/home',
),
Instead of creating subfolder
localhost/subtest/versions/1.0/contact (version).
create two main folder as versions1.0 and versions2.0 like
localhost/versions1.0/contact
localhost/versions2.0/contact
Thanks
chandran nepolean
argonius
(Gogyinsomnia)
October 10, 2013, 12:17pm
6
Thanks chandran.
You are right about that, but I want actually to have only one site accessible by:
localhost/subtest/
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.
argonius
(Gogyinsomnia)
October 10, 2013, 7:25pm
7
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