tags:

views:

44

answers:

2

So i've got the following code:

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);

which is pretty ugly but simple, I'm trying to find a way to deal with multiple files in multiple location's i'm somewhat familiar with bootstraping, but don't fully know the "best practices".

my end goal would be one file that parses a ini file and distributes variables, locations and such to the other files...all files would need to pass thru this file before being loaded. I was looking into setting variables via the .htaccess method but i'm not sure how that works.

any help would be great! (i'm looking for some theory and best practices here ;)

thanks!

A: 

The best way I have done this before is to use Apache's 404 handler and a rewrite. Basically, you tell apache (in the .htaccess) to send all 404's to the index.php (or your bootstrap) and in that file you can determine where they need to go based on what they typed and load the content accordingly..

www.mysite.com/page.html > 404! > index.php > Load data for page.html

If the data for page.html does not exist, then you just throw your custom 404 instead.

Fairly easy to set up and build on.

Christian
A: 

You could use mod_rewrite to link all requests to your index.php

RewriteEngine on
RewriteRule !\.(js|ico|gif|jpg|png|css)$ index.php
  1. http://example.org/test/foo is internally rewritten to http://example.org/index.php
  2. In the $_SERVER array you'll still find the information for /test/foo

Have a look a some popular frameworks. For example Zend Framework.

Philippe Gerber