Home > PHP Framework > YII > body text

How to configure pathinfo mode in yii framework

angryTom
Release: 2020-02-18 11:18:50
Original
2011 people have browsed it

How to configure pathinfo mode in yii framework

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(
        '/'=>'/view',
        '//'=>'/',
        '/'=>'/',
    ),
),
Copy after login

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
Copy after login

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(
        '/'=>'/view',
        '//'=>'/',
        '/'=>'/',
    ),
),
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact [email protected]
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!