【问题标题】:Boostraping using apache and php or another method使用 apache 和 php 或其他方法进行引导
【发布时间】:2009-06-24 05:24:16
【问题描述】:

所以我有以下代码:

ini_set("include_path" , ini_get("include_path") . ":/Library/WebServer/Documents/__CMS/:");
ini_set('display_errors', 'ON');

$base_url = '127.0.0.1';
$lib_dir = '/Library/WebServer/Documents/__CMS/';

header('Location: admin/main.php?base_url='.$base_url.'&lib_dir='.$lib_dir);

这很丑陋但很简单,我试图找到一种方法来处理多个位置的多个文件,我对引导有点熟悉,但不完全了解“最佳实践”。

我的最终目标将是一个解析 ini 文件并将变量、位置等分配给其他文件的文件……所有文件都需要在加载之前通过该文件。我正在研究通过 .htaccess 方法设置变量,但我不确定它是如何工作的。

任何帮助都会很棒! (我在这里寻找一些理论和最佳实践;)

谢谢!

【问题讨论】:

  • 我已经读过你的问题几次了,我真的不明白。你能澄清一下吗?

标签: php apache bootstrapping


【解决方案1】:

我之前做过的最好的方法是使用 Apache 的 404 处理程序和重写。 基本上,您告诉 apache(在 .htaccess 中)将所有 404 发送到 index.php(或您的引导程序),在该文件中,您可以根据输入的内容确定它们需要去哪里并相应地加载内容..

www.mysite.com/page.html > 404! > index.php > 为 page.html 加载数据

如果 page.html 的数据不存在,那么您只需抛出自定义 404。

相当容易设置和构建。

【讨论】:

    【解决方案2】:

    您可以使用 mod_rewrite 将所有请求链接到您的 index.php

    RewriteEngine on
    RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
    
    1. http://example.org/test/foo 内部重写为 http://example.org/index.php
    2. 在 $_SERVER 数组中,您仍然可以找到 /test/foo 的信息

    看看一些流行的框架。例如Zend Framework

    【讨论】:

      猜你喜欢
      • 2019-11-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-04-02
      • 2014-04-11
      • 1970-01-01
      相关资源
      最近更新 更多