How to remove index.php in Yii Framework

后端 未结 9 1702
一个人的身影
一个人的身影 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:40

    taken directly from yii documentation

    Hiding index.php There is one more thing that we can do to further clean our URLs, i.e., hiding the entry script index.php in the URL. This requires us to configure the Web server as well as the urlManager application component.

    We first need to configure the Web server so that a URL without the entry script can still be handled by the entry script. For Apache HTTP server, this can be done by turning on the URL rewriting engine and specifying some rewriting rules. We can create the file /wwwroot/blog/.htaccess with the following content. Note that the same content can also be put in the Apache configuration file within the Directory element for /wwwroot/blog.

    RewriteEngine on
    
    # if a directory or a file exists, use it directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    
    # otherwise forward it to index.php
    RewriteRule . index.php
    

    We then configure the showScriptName property of the urlManager component to be false.

    Now if we call $this->createUrl('post/read',array('id'=>100)), we would obtain the URL /post/100. More importantly, this URL can be properly recognized by our Web application.

    Hope this helps, because solved my issue as well.

提交回复
热议问题