用 PHP 重写 URL 而不是服务器配置 [英] Rewriting URLs in PHP instead of server config
问题描述
我正在寻找一个非常轻量级的路由框架(与 php-skel 一起使用).
I'm looking for a very lightweight routing framework (to go with php-skel).
我想调查的第一件事是在 php 文件(未找到"处理程序)中指定重写规则,其方式与在服务器配置中指定的方式类似.
The first thing I'd like to investigate is specifying rewrite rules in a php file ("not found" handler) in a similar way to how this is specified in the server configs.
这是一个潜在的例子(但我想知道哪些框架提供了这种轻量级的东西):
Here's a potential example (but I'm wanting to know what frameworks provide something this lightweight):
文件 route.php:
File route.php:
route('application/api', '/api/index.php');
route('application', '/application/index.php');
文件应用程序/index.php:
File appplication/index.php:
route(':module/:action', function($module, $action) {
include(__DIR__ . '/' . $module . '/' . $action . '.php');
});
轻量级路由框架/功能或技术有哪些?
What are the lightweight routing frameworks / functions or techniques?
推荐答案
php之道:
http://example.com/index.php/controller/action/variables
$routing = explode("/" ,$_SERVER['PATH_INFO']);
$controller = $routing[1];
$action = $routing[2];
$variables = $routing[3];
这篇关于用 PHP 重写 URL 而不是服务器配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!