[闲聊] PHP 的 routing

楼主: Neisseria (Neisseria)   2016-03-21 23:13:24
这篇不是什么大道理,是无意间发现的
应该也可以归类在 [无用] 吧
如果各位不在意,可以继续看下去
传统上,单页的 PHP 程式是以资料夹结构做为 routing 的方式
url 就像是 http://example.com/hello/user.php
有在写 PHP 程式的人应该都知道这点
不过,使用 PHP 的 web framework,加入了 routing 的功能
也可以规画出像是 http://example.com/hello/john/ 这样的 url
最近用 Slim framework 写了一些小程式
刚好又安装了 HHVM VM,想说用 hhvm 跑跑看
结果 url 会变成 http://example.com/index.php/hello/john/
虽然可以跑,但是不太美丽
但是不想因此就放弃 HHVM
于是用 Laravel 写了一个 Hello, World 等级的小程式
发现 url 又变成好看的 http://example.com/hello/john/
由于 PHP 的 web framework 实在太多了
小弟实在没力气一个个去试
其他的就给有兴趣的人自行去玩吧
[Update]
感谢各位大大提示。我是用内建的 server 去跑
像是 php -S localhost:4000 和 hhvm -m server -p 4000
的确是没想到可以从 server 设定来处理
作者: MangoTW (不在线上)   2016-03-21 23:44:00
那不是 Silm 的问题,你自己要想办法把 index.php 隐藏掉从 Apache 或 Nginx 的配置档着手
作者: teli (You Are)   2016-03-22 00:26:00
这…你应该去看看.htaccess怎么写,了解一下很好玩~key word:url Rewrite
作者: tsao1211 (Sunday)   2016-03-22 01:28:00
因为有些framework会把index.php不显示出来 网站比较好看
作者: imhaha (嘿嘿)   2016-03-22 07:48:00
推teli 简单又方便
作者: herbacin (herbacin)   2016-03-22 21:22:00
apache: htaccess or apache.conf & nginx: nginx.conf

Links booklink

Contact Us: admin [ a t ] ucptt.com