Avatar of Marco Gasi
Marco Gasi
Flag 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
<?php
session_start();
//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.
    }
    break;
    case 'developement': {
        ini_set('display_errors', 'On');
        error_reporting(E_ALL);
    }
    break;
}

//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
date_default_timezone_set('Europe/Rome');
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

Cheers
PHP

Avatar of undefined
Last Comment
Marco Gasi

8/22/2022 - Mon
Marco Gasi

ASKER
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...
ASKER CERTIFIED SOLUTION
Ray Paseur

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Marco Gasi

ASKER
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' (http://www.sitepoint.com/books/phppro1/) 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

Cheers
Marco Gasi

ASKER
Thank you, Ray
I started with Experts Exchange in 2004 and it's been a mainstay of my professional computing life since. It helped me launch a career as a programmer / Oracle data analyst
William Peck