2012-02-21 7 views
1

.htaccess 파일을 작성하여 오류 코드와 함께 색인을 보내고 전송하려고합니다. 예제 index.php? error404 또는 index.php? error501..htaccess를 사용하여 오류 캐치

아래 코드를 사용하여 루트 디렉토리에 오류가 발생할 수 있습니다.

ErrorDocument 404 index.php?error=404 
ErrorDocument 501 index.php?error=501 

예제 http://www.domain.com/file_does_not_exist.php이 작동합니다. 결과 http://www.domain.com/index.php?error=404

문제는 하위 디렉토리에서 index.php 오류를 포착하여 보내는 것입니다.

http://www.domain.com/directory_does_not_exist 또는 http://www.domain.com/directory_and/file_does_not_exist.php.

결과는 http://www.domain.com/directory_does_not_exist/index.php?error=404이며 따라서 index.php의 CSS가 손상되었습니다.

아래 코드를 시도해 보았습니다. URL을 다시 작성하여 index.php로 다시 리디렉션하려고합니다.

RewriteCond $1 !^err[45][0-9][0-9]$ 
RewriteRule ^\/.\/\.php$ /index.php?s=$1 [R] 

AND 

RewriteCond $1 !^err[45][0-9][0-9]$ 
RewriteRule ^([/]?*)\.php$ /index.php?s=$1 [QSA,L] 

어떤 도움을 주시면 감사하겠습니다.

답변

3

다시 쓸 필요가 없습니다. 예제에

ErrorDocument 404 /index.php?error=404 
ErrorDocument 501 /index.php?error=501 

The docs 쇼 절대 URL : 당신의 ErrorDocument 지침 (A /로 시작)에 절대 URL을 사용

지역 웹 - 대한 슬래시 (/)로 시작

의 URL 경로 (DocumentRoot와 관련됨) 또는 클라이언트가 해결할 수있는 전체 URL이어야합니다. 또는 브라우저가 표시 할 메시지를 제공 할 수 있습니다. 예 :

ErrorDocument 500 http://foo.example.com/cgi-bin/tester 
ErrorDocument 404 /cgi-bin/bad_urls.pl 
ErrorDocument 401 /subscription_info.html 
ErrorDocument 403 "Sorry can't allow you access today" 
+0

빠르고 정확한! – undone