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. Apache
Introdução
Estas funções estão somente disponíveis com o PHP rodando como módulo do Apache.
Nota: A variável do servidor PATH_TRANSLATED não mais é criada implicitamente sob a SAPI do Apache 2 em contraste da situação no Apache 1, onde ela tinha o mesmo valor da variável de servidor SCRITP_FILENAME quando ela não era criada pelo Apache. Esta modificação está de acordo com a especificação CGI. Veja o bug #23610 para mais informações.
Instalação
Para instalar o PHP no Apache, veja a seção Apache no capítulo de instalação.
Configurações em execução
O comportamento do módulo PHP sob o Apache é afetado pelas configurações no php.ini. As diretivas de configuração no php.ini podem ser sobrescritas por diretivas php_flag no arquivo de configuração do servidor ou por arquivos .htaccess locais.
Tabela 1. Opções de configuração no Apache
| Nome | Valor Default | Alterabilidade | Descrição |
|---|---|---|---|
| engine | On | PHP_INI_ALL | liga ou desliga a interpretação pelo PHP |
| child_terminate | Off | PHP_INI_ALL | especifica se os scripts PHP podem solicitar a eliminação do processo filho no final da requisição. Detalhes na função apache_child_terminate() |
| last_modified | Off | PHP_INI_ALL | envia a data de modificação do script PHP como um header Last-Modified: |
| xbithack | Off | PHP_INI_ALL | interpreta arquivos marcados executáveis como scripts PHP, independentemente do final do arquivo |
Breve descrição das diretivas de configuração.
- engine boolean
Esta diretiva somente é útil para a versão módulo do Apache do PHP. Ela pode ser usada para ligar ou desligar a interpretação do PHP em nível de diretório ou em nível de servidor virtual. Colocando engine off nos lugares apropriados do arquivo httpd.conf, o PHP pode ser ativado ou desativado.
Tipos Resource
Esta extensão não possui nenhum tipo resource.
Constantes pré-definidas
Esta extensão não possui nenhuma constante.
- Índice
- apache_child_terminate -- Finaliza o processo Apache depois da requisição
- apache_get_modules -- Retorna uma lista de módulos do Apache carregados
- apache_get_version -- Retorna a versão do Apache
- apache_getenv -- Retorna uma variável subprocess_env do Apache
- apache_lookup_uri -- Realiza uma requisição parcial para a URI especificada e retorna todas as informações sobre ela
- apache_note -- Obtém e seta notas de requisição
- apache_request_headers -- Obtem todos os headers HTTP
- apache_reset_timeout -- Reinicializa o timer de escrita do Apache
- apache_response_headers -- Obtêm todos os headers da resposta HTTP
- apache_setenv -- Configura uma variável no ambiente do sub processo Apache
- ascii2ebcdic -- Converte uma string de ASCII para EBCDIC
- ebcdic2ascii -- Converte uma string de EBCDIC para ASCII
- getallheaders -- Obtem todos os headers HTTP
- virtual -- Realiza uma sub-requisição no 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
