Home > Article > PHP Framework > 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'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)
'components' => [ ... 'urlManager' => [ 'enablePrettyUrl' => true, 'showScriptName' => false, 'rules' => [ ], ], ... ],
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!