yii2.0系列三:url美化

来源:互联网 发布:淘宝买银饰可靠吗 编辑:程序博客网 时间:2024/05/16 06:50


        '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 即可
0 0
原创粉丝点击