您的位置:首页 > 编程语言 > PHP开发

yii2.0系列三:url美化

2016-08-01 16:25 309 查看
        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '',
            'rules' => [
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
           ],
        ],

当前配置是,在 apache 中配置了虚拟目录 /ad,所以访问链接:

http://47.88.190.46/ad/index.php/test/test

会被重定向到 controller/TestController 中的 actionTest;由于虚拟目录的关系, index.php 没有被隐藏,可以通过在根目录下 rewrite 把所有未找到的文件重定向到 /ad/index.php 来解决,但是这样破坏了
yii 目录的独立性,所以还是保留了 index.php;

        'urlManager' => [
            'enablePrettyUrl' => true,
            'showScriptName' => false,
            'suffix' => '',
            'rules' => [
                '<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
           ],
        ],

当前配置是,在 apache 中配置了虚拟目录 /ad,所以访问链接:

http://47.88.190.46/ad/index.php/test/test

要隐藏 index.php ,只需要在 .htaccess 文件中添加 RewriteBase /ad 即可
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  php web服务器 yii20