如何在yii框架中自动设置URL友好 [英] how to setup url friendly in yii framework automatically
本文介绍了如何在yii框架中自动设置URL友好的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我刚刚学习yii框架并阅读了本教程 关于 yii如何设置网址
I just learning yii framework and read this tutorial about yii how to setup url
但是我不知道,假设我有10个控制器,是否应该在配置文件中一一定义控制器? 是否有更好的方法为所有控制器设置友好的网址,如www.yoursite.com/yourController/yourAction/yourID?
but I have no idea, suppose i have 10 controllers, should I define one by one controllers in the config file ? is there a better way to setup url friendly like www.yoursite.com/yourController/yourAction/yourID for all controller ?
我认为codeigniter是自动执行的... yii怎么样?
I think codeigniter did that automatically ... how about yii ?
推荐答案
在/protected/config/main.php中添加..
In /protected/config/main.php add..
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName' => false,
),
),
在您的网络根目录中有一个.htaccess..
In your web root an .htaccess..
Options +FollowSymLinks
IndexIgnore */*
RewriteEngine on
# if a directory or a file exists, use it directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# otherwise forward it to index.php
RewriteRule . index.php
这篇关于如何在yii框架中自动设置URL友好的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文