here is a dynamic version of henk_nicolai at REMOVE-THIS at hotmail dot com's code
$req = $_SERVER['REQUEST_URI'];
// Remove rubbish.
$newReq = ereg_replace ( $_SERVER['SCRIPT_NAME'] . '[^?]*', $_SERVER['SCRIPT_NAME'], $req);
if (strlen($newReq) < strlen($req))
{
header ('Location: '.$newReq);
header ('HTTP/1.0 301 Moved Permanently');
die; // Don't send any more output.
}
unset($req);
unset($newReq);
this can be placed at the top of any file that is to be access by the URI.
II. Fonctions Apache
Introduction
Ces fonctions sont disponibles lorsque PHP est utilisé comme module Apache.
Note : Depuis PHP 4.3.2, la variable serveur PATH_TRANSLATED n'est plus configurée automatiquement sous Apache 2 SAPI au contraire de la situation dans Apache 1, où elle est configurée à la même valeur que la variable serveur SCRIPT_FILENAME lorsqu'elle n'est pas peuplée par Apache. Cette modification a été apportée pour être conforme aux spécifications CGI qui fait que la variable serveur PATH_TRANSLATED doit uniquement exister que si PATH_INFO est définie.
Les utilisateurs d'Apache 2 devraient utiliser AcceptPathInfo = On au lieu de httpd.conf pour définir PATH_INFO.
Installation
Pour l'installation de PHP sous Apache, lisez le chapitre d'installation.
Configuration à l'exécution
Le comportement du module PHP d'Apache est configurable dans le fichier php.ini. Les configurations du php.ini peuvent être remplacées par l'option php_flag dans le fichier de configuration du serveur, ou dans les fichiers locaux .htaccess.
Tableau 1. Options de configuration
| Nom | Par défaut | Modifiable | Historique |
|---|---|---|---|
| engine | "1" | PHP_INI_ALL | Disponible depuis PHP 4.0.5. |
| child_terminate | "0" | PHP_INI_ALL | Disponible depuis PHP 4.0.5. |
| last_modified | "0" | PHP_INI_ALL | Disponible depuis PHP 4.0.5. |
| xbit_hack | "0" | PHP_INI_ALL | Disponible depuis PHP 4.0.5. |
Voici un éclaircissement sur l'utilisation des directives de configuration.
- engine booléen
Active ou non l'interpréteur PHP. Cette directive est utile uniquement pour le module Apache. Elle est utilisée par les sites qui souhaitent activer ou désactiver PHP, au cas par cas, par dossier ou par dossier virtuel. En utilisant engine off au bon endroit dans le fichier httpd.conf, PHP peut être activé ou désactivé.
- child_terminate boolean
Spécifie si les scripts PHP peuvent réclamer la fin des processus fils en fin de requête. Voir aussi apache_child_terminate().
- last_modified boolean
Envoie la date de modification des scripts PHP dans l'en-tête HTTP Last-Modified:.
- xbithack boolean
Analyse avec PHP les fichiers exécutables, indépandemment de leur extension.
Types de ressources
Cette extension ne définit aucune ressource.
Constantes pré-définies
Cette extension ne définit aucune constante.
- Table des matières
- apache_child_terminate -- Termine le processus apache après cette requête
- apache_get_modules -- Retourne la liste des modules Apache chargés
- apache_get_version -- Récupère la version d'Apache
- apache_getenv -- Obtient une variable subprocess_env d'Apache
- apache_lookup_uri -- Effectue une requête partielle pour l'URI spécifiée et renvoie toutes les informations
- apache_note -- Affiche ou affecte le paramètre "apache request notes"
- apache_request_headers -- Récupère tous les en-têtes HTTP de la requête
- apache_reset_timeout -- Remet à sa position initiale le temporisateur d'Apache
- apache_response_headers -- Récupère tous les en-têtes de réponse HTTP
- apache_setenv -- Modifie une variable de subprocess_env Apache
- ascii2ebcdic -- Transforme une chaîne ASCII en EBCDIC
- ebcdic2ascii -- Transforme une chaîne EBCDIC en ASCII
- getallheaders -- Récupère tous les en-têtes de la requête HTTP
- virtual -- Effectue une sous-requête Apache
to henk_nicolai
the behaviour you describe is not a "glitch" of apache :-). an url like
"http://my_server.nl/index.php/foo". should return the resource http://my_server.nl/index.php and pass "/foo" as PATH_INFO in the environment.
which is extremely usefull if you use it wisely.
for more info on PATH_INFO and PATH_TRANSLATED, see http://nl2.php.net/reserved.variables . PATH_INFO is not related to the php pathinfo() function
$2c,
*pike
Important info for Apache2 users that have several virtual hosts.
It seems php_flag directive has a different behaviour under Apache 2 (from what it is under 1.3) when used inside <VirtualHost> block.
If you override global php.ini settings with php_flag for one of your virtual host - then your other non-customized virtual hosts may use this overrided settings as well. php_flag records are messed up among different virtual hosts under single Apache 2 server. It may result from Apache 2 multi-thread nature.
Here is an example:
Suppose you have two Virtual hosts: V1 and V2.
For V1 in Apache configuration you use
php_flag magic_quotes_gpc 1
V2 is supposed to use global php.ini settings, so you didn't put any php_flag records into Apache conf for V2 (this worked under Apache 1.3).
And your default php.ini settings are:
php_flag magic_quotes_gpc 0
When you run your server you'll notice that magic quotes is (sometimes) set to On at V2!
The value turns On at V2 when there have been a previous request to V1.
To solve the problem either move php_flag into .htaccess located inside customized virtual host directory OR put php_flag with default settings into all your <VirtualHost> blocks that are not customized. So for V2 put:
php_flag magic_quotes_gpc 0
It is critical to be very carefull with php_flag engine 0.
My configuration is:
PHP 4.3.4, Apache 2.0.50, Linux RedHat 9
My Apache server has a problem when someone enters a URI like: "http://my_server.nl/index.php/". (Note the extra slash.) The server executes the index.php script anyway, which causes the browser directory and the current directory used in the script to be different. And therefore my relative links don't work, and my stylesheet is not loaded. A quick test ("http://www.php.net/manual/en/index.php/") reveals that also this site has this glitch.
When a client requests a directory without the last slash ("http://www.php.net/manual") the server sends a HTTP 301 (Moved Permanently) response with a redirect to the correct URI ("http://www.php.net/manual/"), and my idea was to do the same when the user adds a slash too much:
<?php
$req = $_SERVER['REQUEST_URI'];
// Remove rubbish.
$newReq = ereg_replace ('index.php[^?]*', 'index.php', $req);
if (strlen($newReq) < strlen($req)) {
header ('Location: '.$newReq);
header ('HTTP/1.0 301 Moved Permanently');
die; // Don't send any more output.
}
unset($req); unset($newReq);
... (rest of the script) ...
?>
Replace every occurence of 'index.php' with your filename and you're done. Hope it helps. :-)
(Note: I'm not using fragments in my URI's (like 'index.php#bottom'), and this code may not do what you want if you are using them.)
If you are trying to find a Handler to use with apache's mod_mime functions (e.g. SetHandler). Use the MIME type associated with php.
e.g. SetHandler application/x-httpd-php
