Deliberately trigger a response error code
Moderator: General Moderators
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Deliberately trigger a response error code
How can I go about deliberately instructing Apache 2.0.33 to generate an error "503 Service Unavailable" and then display the ErrorDocument assigned to that error. Modifying configuration files or using PHP is acceptable.
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
maybe..
Code: Select all
header('HTTP/1.0 503 Service Unavailable');Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Cool I'll give that a try.stereofrog wrote:RewriteEngine On
RewriteRule .* - [R=503]
But it won't then display the ErrorDocument will it.scottayy wrote:Code: Select all
header('HTTP/1.0 503 Service Unavailable');
I imagine it would, if you had .htaccess set up that way.ole wrote:Cool I'll give that a try.stereofrog wrote:RewriteEngine On
RewriteRule .* - [R=503]But it won't then display the ErrorDocument will it.scottayy wrote:Code: Select all
header('HTTP/1.0 503 Service Unavailable');
Code: Select all
ErrorDocument 404 /path/to/503.htmlSet Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Correct me if I'm wrong. But once Apache has begun to serve or, in the case of PHP, execute, a file nothing you do inside that file is going to stop it and allow it to start serving another. Once you're into a PHP script you can't then tell Apache to go off and serve a different file instead, although there are things you can do inside PHP to make it seem that way, virutal() for instance. Even by using virtual() I still need to write something that generates a 503 somehow unless I can parse my apache2.conf for the correct ErrorDocument declaration and just include that in. On my server accessing apache2.conf is strictly out of bounds as is the use of virtual() as they both are potentially insecure.I imagine it would, if you had .htaccess set up that way.
Yep I'm going to go give it a whirl now.Seems like more of a hack, though. I think stereofrog's solution (providing it works) would be a better solution.
- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Ahh balls
Code: Select all
RewriteRule: invalid HTTP response code for flag 'R'- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
2.0.33
Perhaps I'm using the wrong status code here. I want to be able to take a site down and have the assigned ErrorDocument be displayed. This drew me to 503:
Edit:
I just tried Redirectand apache said
Perhaps I'm using the wrong status code here. I want to be able to take a site down and have the assigned ErrorDocument be displayed. This drew me to 503:
But it would seem Apache deems 503 to be something that I shouldn't be capable of generating myself. None of the other error codes seem appropriate.Shifflet wrote:503 Service Unavailable
For any case in which the Web server is unable to satisfy the request temporarily, it will use a 503 Service Unavailable status code in its response. It can also include a Retry-After header to indicate when the Web client will be able to try the request again and likely receive a successful response.
Edit:
I just tried Redirect
Code: Select all
Redirect 503 /foo http://www.google.comCode: Select all
Redirect URL not valid for this status- Ollie Saunders
- DevNet Master
- Posts: 3179
- Joined: Tue May 24, 2005 6:01 pm
- Location: UK
Judging from this there's no way just to bounce to the assigned error documents other than rewriting to them directly, so that's what I'm going to do. Once there you can use header() as Scottayy suggested.
- stereofrog
- Forum Contributor
- Posts: 386
- Joined: Mon Dec 04, 2006 6:10 am
Oops, sorry. The behaviour of R=xyz has been changed in 2.2 not 2.0
http://svn.apache.org/viewvc/httpd/http ... rev=571986
http://svn.apache.org/viewvc/httpd/http ... rev=571986