Solved

htaccess and bootstrap file problem

Posted on 2012-03-19
4
689 Views
Last Modified: 2012-03-20
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
0
Comment
Question by:Marco Gasi
  • 3
4 Comments
 
LVL 31

Author Comment

by:Marco Gasi
ID: 37740820
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...
0
 
LVL 108

Accepted Solution

by:
Ray Paseur earned 500 total points
ID: 37742019
Ha! You're not on my blacklist ;-)  I just do not know exactly what to say here.  And with the new EE format it is much harder to answer questions.  I am only able to do about half of what I could do with the older format.

I see many web sites that use frameworks to send all the requests through the index.php script using a GET argument to tell the page what kind of output to produce.  To my way of thinking this is not meaningfully different than having a page with a URL that gives a name to the script, instead of just a get argument and a number or two.  If you're writing a framework, it may make sense to organize the code this way.  But if you're creating a web site with a well-understood purpose and important content it just makes sense to me to use plain-language names for the pages.  I find this less confusing and easier to organize.  I do not find an advantage in using rewrite rules to obscure or change the URLs or to "hide PHP" from the client.  Who cares if you use ASP, ColdFusion, Java, VB, PHP, so long as you get the right information to the client?  What is there to hide?

Anyway, if the goal is to write a framework, making a highly-generalized page structure probably makes sense.  If the goal is to write a web page or a web service, the value of bespoke programming cannot be over-emphasized.  It makes for fast response, and its components are easy to understand and debug.

I don't know if this bit of philosophy is helpful, but it's the way I do my work.  

Best regards, ~Ray
0
 
LVL 31

Author Comment

by:Marco Gasi
ID: 37742447
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
0
 
LVL 31

Author Closing Comment

by:Marco Gasi
ID: 37742449
Thank you, Ray
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
wordpress url rewriting plugin 5 41
Passing variables to stored procedure 3 34
wamp versus xampp 4 43
Method for submitting dynamically created rows 20 11
Password hashing is better than message digests or encryption, and you should be using it instead of message digests or encryption.  Find out why and how in this article, which supplements the original article on PHP Client Registration, Login, Logo…
This article discusses four methods for overlaying images in a container on a web page
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

947 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now