Yii removing application directory name from URL

拥有回忆 提交于 2019-12-22 14:06:41

问题


Okay seems like this is a pretty common problem, but I can't find a definitive solution on the forums.

My Yii is set up like this

/webroot/framework
/webroot/app
/webroot/requirements

The app folder hosts the yii application

however my url looks like : site[dot]com/app/site/index

How do I remove the 'app' portion from the URL.

I tried moving my .htaccess file to the webroot folder and it redirects but 'app' still shows up in the url

Here are the contents of /webroot/.htaccess

<IfModule mod_rewrite.c>
  RewriteEngine On
  RewriteBase /

  # need this for AMZN ELB or get a infinite redirect loop 
  RewriteCond %{HTTP:X-Forwarded-Proto} !https
  RewriteCond %{SERVER_NAME} !^localhost$
  RewriteRule (.*) %{HTTP_HOST}%{REQUEST_URI} [L]

  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule . /app/index.php 
</IfModule>

I would be easy if I could just change my webroot to /webroot/app but I can't control that. Thanks for any help..

This is launched on appfog so I can't control the webroot, or have the framework folder live one directory above the webroot.


回答1:


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




回答2:


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




回答3:


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 ?



来源:https://stackoverflow.com/questions/13636511/yii-removing-application-directory-name-from-url

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