php - Deploying yii2 in a subdirectory -
i deployed yii2 on subdirectory. encountering problems on redirection. on localhost, worked project not in subdirectory, not having problems. when deployed on our live server , put project in subdirectory, having problems.
my problem when visit homepage of site being redirected root of website.
here's example: main site: http://example.com/
yii2 site: http://example.com/myproject/
when try go http://example.com/myproject/, expected redirected @ http://example.com/myproject/login, instead redirected http://example.com/login.
i changed .htaccess one
rewriteengine on  # if directory or file exists, use directly rewritecond %{request_filename} !-f rewritecond %{request_filename} !-d  # otherwise forward index.php rewriterule ^(.*) system/index.php/$1 [qsa,l]   but think 1 wrong though...
i have 1 on web.php
$config = [     'id' => 'basic',     'basepath' => dirname(__file__) . directory_separator . '..',     'defaultroute' => 'site/login',      //... other codes here...   as can see have defaultroute site/login seems keep on redirecting on /login, not in subfolder link.
any how set yii2 in subdirectory
your appreciated. thanks!
the urlmanager doesn't know app not in webserver's root directory.  try setting $config['components']['urlmanager']['baseurl'] project's path:
// in web.php $config = [     'id' => 'basic',     //... other codes here...     'components' => [         'urlmanager' => [             'class' => 'yii\web\urlmanager',                     'baseurl' => 'myproject',         ]     ] ]   btw, shorten basepath definition to
'basepath' => dirname(__dir__),   which should return same directory less (and imho cleaner) code.
Comments
Post a Comment