简体   繁体   中英

Not showing 403 code in status (200 OK) and some page

Code below works for error code 404 but for 403 code is not working. It doesn't show page 403.html and continu to show code 403 in status instead of 200 OK. Why?

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]

To do this you can use

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

You can check out the flags you can set here http://httpd.apache.org/docs/current/mod/mod_rewrite.html#rewriterule And more information on changing the error documents here: http://httpd.apache.org/docs/2.2/mod/core.html#errordocument

Keep your .htaccess like this:

### 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]

Then inside /403.php start with this php code:

<?php
   http_response_code ( 200 );
   # rest of your html code
?>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM