Yii框架的路由配置方法分析
本文實(shí)例講述了Yii框架的路由配置方法。分享給大家供大家參考,具體如下:
取消index.php
這兩種方法都是在自動添加index.php
方法一:使用.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
<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ù)庫操作技巧匯總》
希望本文所述對大家基于Yii框架的PHP程序設(shè)計(jì)有所幫助。
相關(guān)文章
ThinkPHP利用PHPMailer實(shí)現(xiàn)郵件發(fā)送實(shí)現(xiàn)代碼
本文章介紹了關(guān)于在thinkphp中利用了phpmailer來實(shí)現(xiàn)郵件發(fā)送的詳細(xì)教程,有需要的朋友可以參考一下2013-09-09
ThinkPHP公共配置文件與各自項(xiàng)目中配置文件組合的方法
這篇文章主要介紹了ThinkPHP公共配置文件與各自項(xiàng)目中配置文件組合的方法,涉及array_merge函數(shù)將多個(gè)數(shù)組合并的方法,是ThinkPHP項(xiàng)目開發(fā)中非常實(shí)用的技巧,需要的朋友可以參考下2014-11-11
thinkphp5.1框架實(shí)現(xiàn)格式化mysql時(shí)間戳為日期的方式小結(jié)
這篇文章主要介紹了thinkphp5.1框架實(shí)現(xiàn)格式化mysql時(shí)間戳為日期的方式,結(jié)合實(shí)例形式分析了thinkPHP針對mysql時(shí)間戳格式轉(zhuǎn)換的相關(guān)操作技巧,需要的朋友可以參考下2019-10-10
php實(shí)現(xiàn)銀聯(lián)商務(wù)公眾號+服務(wù)窗支付的示例代碼
這篇文章主要介紹了php實(shí)現(xiàn)銀聯(lián)商務(wù)公眾號+服務(wù)窗支付的示例代碼,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2019-10-10
基于PHP Web開發(fā)MVC框架的Smarty使用說明
本篇文章小編為大家介紹,基于PHP Web開發(fā)MVC框架的Smarty使用說明。需要的朋友參考下2013-04-04
分享PHP源碼批量抓取遠(yuǎn)程網(wǎng)頁圖片并保存到本地的實(shí)現(xiàn)方法
本篇文章給大家分享PHP源碼批量抓取遠(yuǎn)程網(wǎng)頁圖片并保存到本地的實(shí)現(xiàn)方法,對批量抓取網(wǎng)頁圖片相關(guān)知識感興趣的朋友一起學(xué)習(xí)吧2015-12-12
ZendFramework框架實(shí)現(xiàn)連接兩個(gè)或多個(gè)數(shù)據(jù)庫的方法
這篇文章主要介紹了ZendFramework框架實(shí)現(xiàn)連接兩個(gè)或多個(gè)數(shù)據(jù)庫的方法,涉及ZendFramework框架配置文件與數(shù)據(jù)庫操作相關(guān)技巧,需要的朋友可以參考下2016-12-12

