---
title: "我是这么理解 php 框架中的route部分"
author: "imjl"
date: "2012-08-07T22:29:39Z"
tags: []
categories: ["编程语言"]
slug: "php-route"
draft: false
lastmod: "2012-08-07T22:29:39Z"
id: 1624529
url: "https://imjl.iteye.com/blog/1624529"
---

一般php的mvc框架都会有route部分，我理解的是将url解析成controller, action, params.

比如 http://localhost/framework/index.php/a/b/?id=1

controller = a
action = b
params 就是id=1

seo效果后，可能是 test.com/a_b_1.html, 也可能是test.com/a/b/1.html.

url解析完成后就到根据特定规则载入controller执行action操作。

和一般url中包含文件夹显示不一样，比如test.com/a/b/1.html，如果没有rewrite，一般就是在test.com这个网站下有个文件夹a，里面还有个文件夹b，最后有个1.html的文件。

至于rewrite写在哪里看各自需要，我是认为应该写在http server配置里，理由：和业务相关，很少改动。