1

how would I change the default 403 forbidden with a 423 locked instead,
when denying someone in htaccess.?

example, usually when you use deny from in htaccess, apache would serve a 403 forbidden error.
is there a way to set what error message is actually served in place of the 403 forbidden?

I have not tried this, but im thinking maybe by defining custom error messages in htaccess might work,
for example,

ErrorDocument 403 /path/423.shtml

But something tells me my server would over ride that by default and still use the 403 error.
and no, i do not have shell access or access to the apache install files.

thanks.

TheFuz
  • 119
  • 9

2 Answers2

0

You're close, but you need a script or something to set the header response. Using the ErrorDocument by itself will still cause the server to return a 403 Forbidden, eventhough the content returned will be what's in /path/423.shtml. You can use php or something to override that. So using the error document:

ErrorDocument 403 /path/423.php

Then in the 423.php file:

<?php

header("HTTP/1.1 423 Locked");

// whatever other content you want returned
?>
Jon Lin
  • 142,182
  • 29
  • 220
  • 220
  • ,if i am presuming right, in your example id be using a php file as an error page.instead of my shtml page. I have other code in use in the shtml page that i doubt would work in a php file as is.like the variables to show the users ip address and browser information and a meta refresh redirect.so im not certain if a php file would be a good idea or not. – TheFuz Nov 19 '13 at 21:02
  • @TheFuz There's 2 ways, you can include php in the shtml, or have the shtml be loaded by the php script. See: http://stackoverflow.com/questions/839272/how-to-include-php-file-in-shtml-pages or http://stackoverflow.com/questions/6537674/how-to-run-shtml-include-in-php – Jon Lin Nov 19 '13 at 21:25
0

If you want to want to do it "pure" (without PHP or Perl code) you will need to use mod_rewrite and utilize the [R=XXX] which means redirect and XXX is the code you want to use, see: http://httpd.apache.org/docs/current/rewrite/flags.html#flag_r

Noam Rathaus
  • 5,405
  • 2
  • 28
  • 37
  • so using the `[R=XXX]` with my example in the question, how would i go about getting it to work with `[R=423,L]` so it redirects from the default `403` to the new `423` sorry im not much of a code guru. – TheFuz Nov 19 '13 at 21:11
  • @TheFuz mod_rewrite can send a specific request to a response code using the `R` flag, but it can't intercept already outgoing 403 responses and change them (can be 403 for any reason, like not having the ability to view directory indexes). – Jon Lin Nov 19 '13 at 21:34
  • @Jon Lin, thanks, can the `R flag` be used for any reference?. or just system error messages. i have a few custom error pages like `bots.shtml`, `spam.shtml`. would `[R=bots]` or `[R=spam]` work same way as the normal error status's ? – TheFuz Nov 19 '13 at 22:13
  • @TheFuz If you want to load "bots", then `RewriteRule ^some-pattern$ /bots.html [L,R=123]`, where "123" is the response code. Not all of them will work, and its behavior is not very well documented – Jon Lin Nov 19 '13 at 22:17