Link to home
Start Free TrialLog in
Avatar of Marco Gasi
Marco GasiFlag for Spain

asked on

htaccess and bootstrap file problem

Hi all, Experts. I need your help urgently.
I'm writing a web application and I'm setting up a bootstrap file following suggestions found on the web. The problem seems to be in the htaccess: or it sends me to the index.php (bootstrap code) and not to the desired page, or it send me to the desired page but bootstrap code is not executed.
Please, give me the trick!

This is is my bootstrap code in index.php
//define our status constant: uncomment wanted option
//define('STATUS', 'production');
define('STATUS', 'developement');

//check what status we have
switch (STATUS) {
    case 'production': {
        ini_set('display_errors', 'Off');
        //and other specific includes, commands, etc.
    case 'developement': {
        ini_set('display_errors', 'On');

//let's set up a root path constant
define('ROOT', getcwd() . DIRECTORY_SEPARATOR);
//define the includes and config folders
define('INCLUDES', ROOT . 'includes' . DIRECTORY_SEPARATOR);
define('CONFIG', ROOT . 'config' . DIRECTORY_SEPARATOR);
define('CLASSES', ROOT . 'classes' . DIRECTORY_SEPARATOR);

//load in the main configuration file
require_once(CONFIG . 'config.php');

Open in new window

This is the required config.php
require_once (CLASSES . 'mgUserManager.php');
require_once (CLASSES . 'mgUploader.php');
require_once (CLASSES . 'mgSearchPlaces.php');
require_once (CLASSES . 'mgSearchResult.php');
require_once (CLASSES . 'mgExceptions.php');
require_once (INCLUDES . 'functions.php');

Open in new window

And these two snippets are the two htaccess tried: the first one redirect to index.php:
  RewriteEngine on
  RewriteBase /
  RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
  php_flag magic_quotes_gpc off

Open in new window

The second leads me to the desired page but without having initialization:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

RewriteRule ^(.*)$ index.php?route=$1 [L,QSA]

Open in new window

I'll be very grateful to everyone for any help

Avatar of Marco Gasi
Marco Gasi
Flag of Spain image


How it's possible no one want to answer to my question? It seems like I'm in the blacklist of all experts and I don't know why...
Avatar of Ray Paseur
Ray Paseur
Flag of United States of America image

Link to home
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Eh, eh, I'm happy to be not in your blacklist!
I'm not writing a new framework, and I didn't believe using rewrite rules only had the goal to hide '.php' or '.asp' from urls.
My goal was another. I usually use a require_once('common.php') as you do but reading the Sitepoint book 'PHP Master Write Cutting-Edge Code' ( I learned about bootstrap file. Well, I learned nothing, but the author has mentioned the bootstrap file talking about the writing of custom exception handler. So I googled and it seems that every oop web app should refer to a bootstrap file, even almost always articles are referring to some framework. Well, I thought a bootstrap file were a more friendly tecnique to initilize and have always available all constant, session variable etc, without that one line of code in each script.

Your 'bit of philosophy' clarifies my misunderstanding, so it is very helpful. I'll do in the dear old way.

Thank you very mutch, Ray

Thank you, Ray