[英]Not showing 403 code in status (200 OK) and some page
以下代碼適用於錯誤代碼404,但不適用於403代碼。 它不會顯示403.html頁面,而是繼續顯示狀態為403的代碼,而不是200 OK。 為什么?
Deny from adsl.eunet.rs
RewriteEngine On
RewriteBase /
RewriteRule ^403\.html/?$ - [L]
# If the requested file doesnt exist
# and if the requested file is not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . 403.html [L]
為此,您可以使用
ErrorDocument 403 /403.html # define the error document
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^ - [F,L] # match anything, F means return 403 Forbidden, L - last
您可以在此處查看設置的標志http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule以及有關更改錯誤文檔的更多信息, 請參見 : http : //httpd.apache.org /docs/2.2/mod/core.html#errordocument
保持您的.htaccess像這樣:
### Deny from adsl.eunet.rs
ErrorDocument 403 /403.php
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_ADDR} =194.247.196.20
RewriteRule !^(404|403)\. - [F]
RewriteRule ^(404|403)\. - [L]
# If the requested file doesnt exist
# and if the requested file is not an existing directory
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . 404.html [L]
然后在/403.php
以以下php代碼開頭:
<?php
http_response_code ( 200 );
# rest of your html code
?>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.