How to configure the pathinfo mode in the yii framework
After deploying an application built by the Yii framework for the first time, the framework does not use the PathInfo format by default URL, but in the form of http://yourdomain.com/index.php?r=account/login. This kind of URL is not only unsightly, but also not conducive to SEO, so here is how to use the PathInfo form in Yii. URL (Note: The development environment is based on wampserver2.4).
1) Open the protected/config/main.php configuration file and remove the comment from the following urlManager code:
'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>', ), ),
2) After removing it, we can use something like http:// Use a URL in the form of yourdomain.com/index.php/controller/action to access the application, but then we have to hide the index.php in the middle;
Recommended related article tutorials: yii Tutorial
3) Add a file named .htaccess in the root directory of the application and write the following content:
Options +FollowSymLinks IndexIgnore */* 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
4) Enable the rewrite module of apache, in httpd Find #LoadModule rewrite_module modules/mod_rewrite.so in .conf and remove the "#" in front;
5) Restart apache;
6) Continue to edit the main.php file, and add the Add an element to the array of urlManager:
'urlManager' => array( 'urlFormat' => 'path', 'showScriptName' => false, // 添加这一行 'rules' => array( '<controller:\w+>/<id:\d+>'=>'<controller>/view', '<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>', '<controller:\w+>/<action:\w+>'=>'<controller>/<action>', ), ),
7) Complete!
For more yiiIntroduction to Programming technologies, please continue to pay attention to the PHP Chinese website! !
The above is the detailed content of How to configure pathinfo mode in yii framework. For more information, please follow other related articles on the PHP Chinese website!