我正在构建一个基于http://www.youtube.com/watch?v=Aw28-krO7ZM(创建您自己的 MVC - Jream)的自定义 PHP MVC 框架,但是我使用 IIS 作为我的本地网络服务器。我已经安装了 Url Rewrite Module 并添加了以下规则:
<rewrite>
<rules>
<rule name="MyRewriteRule" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false"/>
<action type="Rewrite" url="index.php?url={R:1}" appendQueryString="true" />
<conditions>
<add input="{REQUEST_FILENAME}" matchType="IsFile" />
<add input="{REQUEST_FILENAME}" matchType="IsDirectory" />
</conditions>
</rule>
</rules>
</rewrite>
MVC 的结构如下:
application(folder)
config(folder), controllers(folder), view(folder), model(folder) etc...
public(folder)
css, images, js, etc...
index.php
web.config
该 urlhttp://localhost:8080/MyApp/
工作得很好,但http://localhost:8080/MyApp/index/
失败了……或者/home
,/legal
任何与此相关的控制器。在自定义 Bootstrap.php 文件中执行以下代码:
<?php class Bootstrap{
function __construct(){
//format the url
$url=isset($_GET['url'])? $_GET['url']: null; //when a controller is specified it fails before even hitting this point, im sent to the error 404 page before getting past here
$url=rtrim($url,'/');
$url=explode('/',$url);
if(empty($url[0])){
require 'application/controllers/index.php';
//.....blah blah blah
}
//more irrelevant code...
require 'application/controllers/'.url[0]'.php';
//more irrelevant code...
}} ?>