How to remove index.php in Yii Framework

后端 未结 9 1609
一个人的身影
一个人的身影 2020-12-08 22:56

\"enterHey guyz i am a newbie in Yii framework. I want to remove the index.php from my urls. F

相关标签:
9条回答
  • 2020-12-08 23:23

    If you also want to remove /index from the main page URL, add ''=>'site/index' to the top of your urlManager rules, like so:

    'urlManager'=>array(
        'urlFormat'=>'path',
        'showScriptName' => false,
        'rules'=>array(
            ''=>'site/index',
            '<action>'=>'site/<action>',
    
    0 讨论(0)
  • 2020-12-08 23:26

    Do these 3 steps:

    1. Enable Url re-writing on Apache.

    2. Place .htaccess on root of your project

    RewriteEngine on

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    RewriteRule . index.php
    
    1. In your configuration protected/config/main.php set showScriptName to false like this to your url manager components >> urlManager
    'urlManager'=>array(
      'urlFormat'=>'path',
      'rules'=>array(
          '<controller:\w+>/<id:\d+>'=>'<controller>/view',
          '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
          '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
      ),
      'showScriptName'=>false,
    )
    
    0 讨论(0)
  • 2020-12-08 23:26

    I just came across this thread but found that in order to get it working I not only had to follow the instrucitons for adding the .htaccess file but also had to uncomment the section below from my main config file (\protected\config\main.php):

            // uncomment the following to enable URLs in path-format
    
        'urlManager'=>array(
            'urlFormat'=>'path',
            'rules'=>array(
                '<controller:\w+>/<id:\d+>'=>'<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
            ),
        ),
    
    0 讨论(0)
  • 2020-12-08 23:29

    modify apache config values

    AllowOverride none to AllowOverride ALL

    in httpd.conf or httpd-vhosts.conf

    0 讨论(0)
  • 2020-12-08 23:35

    I had also this problem today when I have shifted my project to linux server. I did all ways that are shown, but not helped. Then, I have copied .htaccess file to protected directory also, then it worked.

    0 讨论(0)
  • 2020-12-08 23:37

    Try this

    A good description is available here

    http://www.yiiframework.com/doc/guide/1.1/en/topics.url#hiding-x-23x

    0 讨论(0)
提交回复
热议问题