开发者社区> 问答> 正文

请问thinkphp是如何实现url的rewrite?

thinkphp 如何实现 "http://localhost/index.php?/模块/操作&quo... 变为 "http://localhost/模块/操作"
我想把URL改成这种形式,看起来会比较舒服,但是不知道怎么实现。
是在conifg里面加参数,还是在nginx里面用rewrite?

展开
收起
落地花开啦 2016-06-12 16:17:17 2206 0
1 条回答
写回答
取消 提交回答
  • 喜欢技术,喜欢努力的人

    1.在配置文件将URL模式改成

    'URL_MODEL'          => '2', //REWRITE模式

    2.Apache服务器的话,将下面的内容保存为.htaccess文件放到入口文件的同级目录

    <IfModule mod_rewrite.c>
    RewriteEngine on
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^(.*)$ index.php/$1 [QSA,PT,L]
    </IfModule>

    Nginx.conf中配置

    location / { // …..省略部分代码
       if (!-e $request_filename) {
       rewrite  ^(.*)$  /index.php?s=$1  last;
       break;
        }
     }
    2019-07-17 19:34:27
    赞同 展开评论 打赏
问答排行榜
最热
最新

相关电子书

更多
低代码开发师(初级)实战教程 立即下载
冬季实战营第三期:MySQL数据库进阶实战 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载