Solved

htaccess and bootstrap file problem

Posted on 2012-03-19
4
724 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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 110

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

751 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