|
|
|
| Допустим у нас есть index.php (куда перенаправляются все запросы) и error.php(страница 404 ошибки)
адрес : http://site.ru/xx-xx-xx/ прогоняем через шаблон : RewriteRule ^([A-Za-z0-9\-]+)/$ index.php?var=$1 [L]
$v = $_GET['var'];
if ($v!=' xx-xx-xx')
{
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
header('Location: /error.php');
exit();
}
при ошибке показывается посетителю страничка error.php(все правильно!!!)
смотрим HTTP протокол:
http://site.ru/ xx-ZZZ-xx/ 302 Found
http://site.ru/error.php 200 OK
|
для людей понятно ,для робота--документ существует но временно перемещен
Другой вариант
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
http://site.ru/ xx-ZZZ-xx/ 404 Not Found
|
для робота правильно,для посетителя нет
еще вариант http://site.ru/ xx-;№-xx/
тут вступает в работу модреврайт
ErrorDocument 404 http://site.ru/error.php?404
получаем страничку с сообщением но
http://site.ru/ xx-;№-xx/ 302 Found
http://site.ru/error.php?404 301 Moved Permanently
http://site.ru/error.php?404 200 OK
|
опять не то....
как получить http://site.ru/ xx-ZZZ-xx/ 404 Not Found и показать страничку ошибки | |
|
|
|
|
|
|
|
для: serjinio
(21.08.2009 в 04:09)
| | мне кажется дирректива Apache ErrorDocument специально для того чтобы правильнее обрабатывать ошибки
обычно такой ответ при 404
HTTP/1.1 404 Not Found
Date: Fri, 21 Aug 2009 17:55:48 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.11-dev
Content-Length: 440
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /xxxx was not found on this server.</p>
<p>Additionally, a 404 Not Found
error was encountered while trying to use an ErrorDocument to handle the request.</p>
<hr>
<address>Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.11-dev Server at src Port 80</address>
</body></html>
|
вообщето такой :)
HTTP/1.1 404 Not Found
Date: Fri, 21 Aug 2009 18:09:15 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.11-dev
X-Powered-By: PHP/5.2.11-dev
Set-Cookie: SN=1; expires=Fri, 21-Aug-2009 19:09:15 GMT; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Transfer-Encoding: chunked
Content-Type: text/html
<pre>
test1
0.0186081<hr/>
| первый был с несуществующим файлом в ErrorDocument 404
вот стандартный ответ
HTTP/1.1 404 Not Found
Date: Fri, 21 Aug 2009 18:13:37 GMT
Server: Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.11-dev
Content-Length: 321
Content-Type: text/html; charset=iso-8859-1
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML 2.0//EN">
<html><head>
<title>404 Not Found</title>
</head><body>
<h1>Not Found</h1>
<p>The requested URL /xxxx was not found on this server.</p>
<hr>
<address>Apache/2.2.11 (Win32) DAV/2 mod_ssl/2.2.11 OpenSSL/0.9.8i PHP/5.2.11-dev Server at src Port 80</address>
</body></html>
|
| |
|
|
|
|
|
|
|
для: serjinio
(21.08.2009 в 04:09)
| | правила хорошего тона запрещают применять клиентский редирект со страницы, вызвавшей 404-ю ошибку. | |
|
|
|
|
|
|
|
для: Trianon
(22.08.2009 в 00:12)
| | Тогда я вижу только два варианта
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
exit('<h1>Error 404 Несуществующая страница.</h1><p>К сожалению, запрошенный Вами документ не существует.Возможно этот файл был удален или переименован.</p><p>А пока предлагаем Вам пройти на <a href="http://www.site.ru/">первую</a> страницу. </p>');
|
либо
header('HTTP/1.1 404 Not Found');
header("Status: 404 Not Found");
include_once ('error.php');
exit();
а сам error.php
<?
header("Expires: Mon, 26 Jul 1997 05:00:00 GMT");
header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT");
header("Cache-Control: no-cache, must-revalidate");
header("Pragma: no-cache");
echo "<h1>Error 404 Несуществующая страница.</h1>";
|
| |
|
|
|
|
|
|
|
для: serjinio
(22.08.2009 в 07:52)
| | А создать файл .htaccess и там написать
ErrorDocument 401 /errors/error_401.html
ErrorDocument 403 /errors/error_403.html
ErrorDocument 404 /errors/error_404.html
ErrorDocument 500 /errors/error_500.html
|
Никак? | |
|
|
|
|
|
|
|
для: neadekvat
(22.08.2009 в 11:59)
| | как.. а если внимательно прочитать с самого начала... | |
|
|
|