Home  >  Article  >  PHP Framework  >  How to set pseudo-static in yii framework

How to set pseudo-static in yii framework

王林
王林Original
2020-02-17 17:44:493958browse

How to set pseudo-static in yii framework

Apache server configuration

Modify the httpd.conf configuration file

1. Remove the comment # in front of LoadModule rewrite_module modules/mod_rewrite.so .

2. Add the following content:

<Directory "path/to/basic/web">
    # use mod_rewrite for pretty URL support
    RewriteEngine on
    # If a directory or a file exists, use the request directly
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    # Otherwise forward the request to index.php
    RewriteRule . index.php

    # ...other settings...
</Directory>

Note that path/to/basic/web is changed to your root directory, and finally don’t forget to restart the apache server.

(Recommended tutorial: yii framework)

Nginx server configuration

Modify the nginx.conf configuration file in the server{} corresponding to the domain name Add the following content:

location / {
    # Redirect everything that isn&#39;t a real file to index.php
    try_files $uri $uri/ /index.php$is_args$args;
}

Finally don’t forget to reload the configuration file.

yii2 code configuration

Modify config/web.php and add the following content in the components array (remove the comments before and after)

&#39;components&#39; => [
    ...
    &#39;urlManager&#39; => [
        &#39;enablePrettyUrl&#39; => true,
        &#39;showScriptName&#39; => false,
        &#39;rules&#39; => [
        ],
    ],
    ...
],

Refresh the web page at this time. You can see that the form of the connection has changed. At this time, the form /index.php?r=controller/action will be changed to /controller/action by default (if it contains parameters, /index.php?r=controller/action&... will be changed to /controller/action ?...).

For more programming related content, please visit the Programming Tutorial column of the php Chinese website!

The above is the detailed content of How to set pseudo-static in yii framework. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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 admin@php.cn