Yii框架的路由配置方法分析
本文實(shí)例講述了Yii框架的路由配置方法。分享給大家供大家參考,具體如下:
取消index.php
這兩種方法都是在自動(dòng)添加index.php
方法一:使用.htaccess
添加.htaccess文件 與index.php同級(jí)
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
<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配置
'urlManager' => [
//美化路由
'enablePrettyUrl' => true,
//不啟用嚴(yán)格解析
'enableStrictParsing' => false,
//index.php是否顯示
'showScriptName' => false,
//偽靜態(tài)化 seo
'suffix' => '.html',
//美化規(guī)則
'rules' => [
//第一條:文章詳細(xì)頁
'<controller:\w+>/<id:\d+>'=>'<controller>/detail',
//第二條:文章列表頁
'post'=>'post/index',
],
],
更多關(guān)于Yii相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Yii框架入門及常用技巧總結(jié)》、《php優(yōu)秀開發(fā)框架總結(jié)》、《smarty模板入門基礎(chǔ)教程》、《php面向?qū)ο蟪绦蛟O(shè)計(jì)入門教程》、《php字符串(string)用法總結(jié)》、《php+mysql數(shù)據(jù)庫操作入門教程》及《php常見數(shù)據(jù)庫操作技巧匯總》
希望本文所述對(duì)大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
Yii2實(shí)現(xiàn)增刪改查后留在當(dāng)前頁的方法詳解
PHP使用星號(hào)替代用戶名手機(jī)和郵箱的實(shí)現(xiàn)代碼
PHP中把數(shù)據(jù)庫查詢結(jié)果輸出為json格式簡(jiǎn)單實(shí)例
根據(jù)ip調(diào)用新浪api獲取城市名并轉(zhuǎn)成拼音

