Analysis of Route Configuration Method in Yii Framework
- 2021-12-21 04:22:49
- OfStack
This paper describes the routing configuration method of Yii framework with examples. Share it for your reference, as follows:
Cancel index. php
Both methods automatically add index. php
Method 1: Use. htaccess
Adding. htaccess file sibling with index. php
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
Method 2: vhost
<VirtualHost *:80>
ServerName public.oa.com
DocumentRoot "D:\phpStudy\PHPTutorial\WWW\OA\frontend\web"
<Directory "D:\phpStudy\PHPTutorial\WWW\OA\frontend\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
# use index.php as index file
DirectoryIndex index.php
# ...other settings...
# Apache 2.4
Require all granted
## Apache 2.2
# Order allow,deny
# Allow from all
</Directory>
</VirtualHost>
Yii Configuration
'urlManager' => [
// Beautify routing
'enablePrettyUrl' => true,
// Strict resolution is not enabled
'enableStrictParsing' => false,
//index.php Whether to display
'showScriptName' => false,
// Pseudo-static seo
'suffix' => '.html',
// Beautify rule
'rules' => [
// No. 1 1 Article : Article detail page
'<controller:\w+>/<id:\d+>'=>'<controller>/detail',
// No. 1 2 Article: Article List Page
'post'=>'post/index',
],
],
For more readers interested in Yii related contents, please check the topics on this site: "Introduction to Yii Framework and Summary of Common Skills", "Summary of Excellent Development Framework of php", "Introduction to smarty Template", "Introduction to php Object-Oriented Programming", "Summary of Usage of php String (string)", "Introduction to php+mysql Database Operation" and "Summary of Common Database Operation Skills of php"
I hope this article is helpful to the PHP programming based on Yii framework.