Yii removing application directory name from URL

旧街凉风 提交于 2019-12-06 12:38:43

May be you can move all files from /webroot/app to /webroot/ (and place yii at /webroot/yii).

I solved it by going on the config like config/main.php and putting:

'request'=>array(
        'baseUrl'=>'',

    ),
     'urlManager'=>array(
        'baseUrl'=>'',
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'appendParams' => true,
        'rules'=>array(

        ),
    ),  'request'=>[
        'baseUrl'=>'',

    ],
     'urlManager'=>array(
        'baseUrl'=>'',
        'urlFormat'=>'path',
        'showScriptName'=>false,
        'appendParams' => true,
        'rules'=>array(

        ),
    ),

Just came back to Yii and faced this problem again

Brainfeeder

I posted a similar question. Placing the 'app' contents in webroot/ however is not an option for me because I need it to be portable and in the near future I'll have other 'apps' in the webroot/ running on the same webroot/framework.

I managed to redirect example.com to example.com/app and had the /app part removed from the URL. I'm redirected to the default controller/action. But when I click on a link to (e.g.) example.com/site/login it still brings me to the default controller/action.

My webroot/.htaccess looks like this:

RewriteEngine on

RewriteCond $1 !^application/
# if a directory or a file exists, use it directly
RewriteCond %{DOCUMENT_ROOT}/application/$1 -f [OR]
RewriteCond %{DOCUMENT_ROOT}/application/$1 -d
RewriteRule ^(.*)$ application/$1 [L]

# otherwise forward it to index.php
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{HTTP_HOST} ^(www.)?example.com$
# RewriteRule ^.*$ application/index.php does not 'remove' the directory with this??
RewriteRule ^$ application [L]

Maybe it helps you out? And since I'm not that much of a .htaccess expert I was wondering if you found a better solution by now ?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!