【问题标题】:404 page when defining Controller and Action in custom PHP MVC in IIS在 IIS 中自定义 PHP MVC 中定义 Controller 和 Action 时出现 404 页面
【发布时间】:2012-10-26 06:10:33
【问题描述】:

我正在构建一个基于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

网址http://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...
     }} ?>

【问题讨论】:

    标签: php model-view-controller iis-7 url-rewriting web-config


    【解决方案1】:

    开始改变

    require 'application/controllers/'.url[0]'.php';

    require 'application/controllers/'.$url[0]'.php';

    【讨论】:

      猜你喜欢
      • 2013-07-31
      • 2011-08-05
      • 2016-01-13
      • 1970-01-01
      • 2015-06-15
      • 2021-02-07
      • 2011-01-02
      • 2014-08-06
      • 1970-01-01
      相关资源
      最近更新 更多