Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

htaccess and bootstrap file problem

Posted on 2012-03-19
4
Medium Priority
?
769 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 111

Accepted Solution

by:
Ray Paseur earned 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

These days socially coordinated efforts have turned into a critical requirement for enterprises.
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

722 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