我不明白。我在.htaccess
中设置了404错误,当我输入类似error.php
http://{localhost}/mywebiste/xxx/xxx/xxx/xxx/
但是我收到了这个错误,
Notice: Undefined index: REDIRECT_URL in C:\...
Notice: Undefined index: REDIRECT_STATUS in C:\...
有,
$_SERVER["REDIRECT_URL"];
$_SERVER['REDIRECT_STATUS'];
htaccess的,
RewriteEngine on
ErrorDocument 404 http://{localhost}/projects/.../error.php
error.php,
$redirect_url = $_SERVER["REDIRECT_URL"];
$status = $_SERVER['REDIRECT_STATUS'];
有什么想法吗?
我已经尝试过这两个网站的代码,但没有一个可以使用,
另外,我在使用EasyPHP Devsever。我想检查是否有
print_r($_SERVER);
我明白了,
Array
(
[TMP] => C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/binaries/tmp
[HTTP_HOST] => localhost
[HTTP_USER_AGENT] => Mozilla/5.0 (Windows NT 6.1; WOW64; rv:33.0) Gecko/20100101 Firefox/33.0
[HTTP_ACCEPT] => text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8
[HTTP_ACCEPT_LANGUAGE] => en-GB,en;q=0.5
[HTTP_ACCEPT_ENCODING] => gzip, deflate
[HTTP_COOKIE] => PHPSESSID=204j1jvbinr4j1i0ebg9eq0ue5
[HTTP_CONNECTION] => keep-alive
[PATH] => C:\Program Files (x86)\EasyPHP-DevServer-14.1VC11\binaries\php\php_runningversion;C:\Windows\system32;C:\Windows;C:\Windows\System32\Wbem;C:\Windows\System32\WindowsPowerShell\v1.0\;C:\Program Files\WIDCOMM\Bluetooth Software\;C:\Program Files\WIDCOMM\Bluetooth Software\syswow64;\;C:\Program Files (x86)\Sony\VAIO Startup Setting Tool;C:\Program Files (x86)\Common Files\Roxio Shared\10.0\DLLShared\;C:\Program Files (x86)\Common Files\Roxio Shared\DLLShared\;C:\Program Files (x86)\QuickTime\QTSystem\;C:\Program Files\Java\jdk1.8.0_05\bin;C:\Program Files\nodejs\;C:\Program Files (x86)\Git\cmd;C:\Users\lau_thiamkok\AppData\Roaming\npm;C:\Program Files\nodejs;C:\Program Files (x86)\Git;C:\PROGRA~2\EASYPH~1.1VC\Apache\bin;C:\PROGRA~2\EASYPH~1.1VC\PHP
[SystemRoot] => C:\Windows
[COMSPEC] => C:\Windows\system32\cmd.exe
[PATHEXT] => .COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC
[WINDIR] => C:\Windows
[SERVER_SIGNATURE] =>
[SERVER_SOFTWARE] => Apache/2.4.7 (Win32) PHP/5.5.8
[SERVER_NAME] => localhost
[SERVER_ADDR] => 127.0.0.1
[SERVER_PORT] => 80
[REMOTE_ADDR] => 127.0.0.1
[DOCUMENT_ROOT] => C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb
[REQUEST_SCHEME] => http
[CONTEXT_PREFIX] =>
[CONTEXT_DOCUMENT_ROOT] => C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb
[SERVER_ADMIN] => admin@127.0.0.1
[SCRIPT_FILENAME] => C:/Program Files (x86)/EasyPHP-DevServer-14.1VC11/data/localweb/projects/tests/php-boilerplate/404/basic/error.php
[REMOTE_PORT] => 55762
[GATEWAY_INTERFACE] => CGI/1.1
[SERVER_PROTOCOL] => HTTP/1.1
[REQUEST_METHOD] => GET
[QUERY_STRING] => code=404
[REQUEST_URI] => /projects/tests/php-boilerplate/404/basic/error.php?code=404
[SCRIPT_NAME] => /projects/tests/php-boilerplate/404/basic/error.php
[PHP_SELF] => /projects/tests/php-boilerplate/404/basic/error.php
[REQUEST_TIME_FLOAT] => 1416567060.231
[REQUEST_TIME] => 1416567060
)
但我没有在the list here中看到REDIRECT_*
。
我是如何让REDIRECT_*
在我的localhost中工作的?
答案 0 :(得分:1)
您可以避免在http://
指令中使用完整的ErrorDocument 404
来获取这两个值:
ErrorDocument 404 /projects/full/path/to/error.php
使用此功能,您将看到填充的这两个值:
$_SERVER["REDIRECT_URL"]; // /mywebiste/xxx/xxx/xxx/xxx/
$_SERVER['REDIRECT_STATUS']; // 404