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.
아파치 함수
소개
이 함수들은 PHP를 아파치 모듈로 실행할때만 사용할 수 있습니다.
Note: PHP 4.3.2부터는, 아파치 1에서의 상황과는 달리 아파치 2 SAPI에서는 PATH_TRANSLATED를 자동적으로 설정하지 않습니다. 이전에는 아파치가 생성하지 않았을 때는, SCRIPT_FILENAME와 같은 값으로 설정했었습니다. 이 변경은 PATH_TRANSLATED는 PATH_INFO가 정의되었을 때만 존재한다는 CGI 규격에 따르기 위한 것입니다. 아파치 2 사용자는 PATH_INFO를 정의하기 위해서 httpd.conf 안에 AcceptPathInfo = On를 사용할 수 있습니다.
설치
아파치에 PHP를 설치하기 위해서는 설치 장을 참고하십시오.
실행시 설정
아파치 PHP 모듈의 동작은 php.ini의 설정에 영향을 받습니다. php.ini의 환결 설정은 서버 환경 설정 파일이나 .htaccess 파일의 php_flag 설정을 통하여 변경할 수 있습니다.
Example#1 .htaccess를 이용해서 PHP 파싱을 끄기
php_flag engine off
| 이름 | 기본값 | 설정권한 | 변경점 |
|---|---|---|---|
| engine | "1" | PHP_INI_ALL | PHP 4.0.5부터 사용할 수 있습니다. |
| child_terminate | "0" | PHP_INI_ALL | PHP 4.0.5부터 사용할 수 있습니다. |
| last_modified | "0" | PHP_INI_ALL | PHP 4.0.5부터 사용할 수 있습니다. |
| xbithack | "0" | PHP_INI_ALL | PHP 4.0.5부터 사용할 수 있습니다. |
위 설정 지시어에 대한 간단한 설명입니다.
- engine boolean
-
PHP 처리를 켜거나 끕니다. 이 지시어는 PHP의 아파치 모듈에 유용합니다. PHP 파싱을 사이트의 디렉토리 단위나 버추얼 서버 단위로 켜거나 끌 수 있습니다.
engine off를 httpd.conf 파일의 적절한 위치에 놓음으로써, PHP의 사용 여부를 결정할 수 있습니다. - child_terminate boolean
-
PHP 스크립트가 종료시에 자식 프로세스의 종료를 요청할 지 지정합니다. apache_child_terminate()를 참고하십시오.
- last_modified boolean
-
PHP 스크립트의 변경일을 Last-Modified: 헤더로 전송합니다.
- xbithack boolean
-
실행 비트가 설정된 파일을 PHP가 파일 끝에 신경쓰지 않고 파싱하게 합니다.
자원형
이 확장은 리소스형을 정의하지 않습니다.
예약 상수
이 확장은 상수를 정의하지 않습니다.
Table of Contents
- apache_child_terminate — 이 요청 후에 아파치 프로세스를 종료한다.
- apache_get_modules — 불러진 아파치 모듈의 목록을 얻습니다.
- apache_get_version — 아파치 버전을 가져옵니다.
- apache_getenv — 아파치 서브프로세스의 환경 변수를 가져옵니다.
- apache_lookup_uri — 특정한 URI에 대한 부분 요청을 실행하고 그에 대한 모든 정보를 반환한다.
- apache_note — 아파치의 요청 노트를 얻거나 설정한다.
- apache_request_headers — 모든 HTTP 요청 헤더를 가져옵니다.
- apache_reset_timeout — Reset the Apache write timer
- apache_response_headers — 모든 HTTP 응답 헤더를 가져옵니다.
- apache_setenv — 아파치의 서브프로세스의 환경 변수를 설정합니다.
- ascii2ebcdic — 문자열을 ASCII에서 EBCDIC로 변환한다.
- ebcdic2ascii — 문자열을 EBCDIC에서 ASCII로 변환한다.
- getallheaders — 모든 HTTP 요청 헤더를 가져옵니다.
- virtual — 아파치 하위 요청을 실행합니다.
아파치
29-Nov-2005 12:41
02-Nov-2005 08:16
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
27-Aug-2004 11:44
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
20-Nov-2002 09:03
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.)
11-Jan-2002 08:40
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
