Yii框架路由配置概述
本内容分享了Yii框架中关于路由配置的具体实践方案,旨在为开发者提供参考与借鉴。
消除URL中的index.php入口文件
消除URL路径中出现的index.php入口文件
上述提及的两种技术手段均能自动处理并添加index.php到请求路径中(注:原文语境指默认行为或需取消的行为,此处保留原意逻辑,实际目的是取消它)
使用.htaccess文件隐藏入口
第一种方案:利用.htaccess文件进行配置
创建.htaccess配置文件,并将其放置在与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
通过vhost虚拟主机配置隐藏入口
第二种方案:通过vhost虚拟主机环境进行设置
ServerName public.oa.com
DocumentRoot "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
Yii框架urlManager组件配置详解
Yii框架内部的相关配置项调整
'urlManager' => [
//美化路由
'enablePrettyUrl' => true,
//不启用严格解析
'enableStrictParsing' => false,
//index.php是否显示
'showScriptName' => false,
//伪静态化 seo
'suffix' => '.html',
//美化规则
'rules' => [
//第一条:文章详细页
'/'=>'/detail',
//第二条:文章列表页
'post'=>'post/index',
],
],
期望上述关于Yii框架PHP程序设计的经验分享能对各位读者有所助益。