首页 > Web开发 > 详细

Yii 2 修改 URL 模式为 PATH 模式,并隐藏index.php

时间:2017-02-11 13:47:05      阅读:323      评论:0      收藏:0      [点我收藏+]

美化URL很重要,URL 看起来顺眼,JJ就不疼。废话不多说,两步搞定。
第一:在配置文件加上 urlManager项,看代码:

 ‘urlManager‘=>[
    ‘class‘ => ‘yii\web\UrlManager‘,
    ‘enablePrettyUrl‘ => true,
    ‘showScriptName‘ => false,
    ‘rules‘=>[
	‘<controller:(post|comment)>/<id:\d+>/<action:(create|update|delete)>‘ =>‘<controller>/<action>‘,
	‘<controller:(post|comment)>/<id:\d+>‘ => ‘<controller>/read‘,
	‘<controller:(post|comment)>s‘ => ‘<controller>/list‘,
	     ],
     ],

第二,在index.php同级目录下新建.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

好了,就是这么轻松。我是YiiSoEasy,胖纸囧是我小弟。

Yii 2 修改 URL 模式为 PATH 模式,并隐藏index.php

原文:http://www.cnblogs.com/handongyu/p/6389044.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!