WebFaction
Community site: login faq

I have a site with only static HTML pages and a Apache .htaccess file.

I have a custom 404 error page to redirect using the following Apache directive

ErrorDocument 404 /custom_404.html

The custom HTML page is served by nginx, and returns a wrong HTTP Status Code. It returns HTTP/1.1 200 OK instead of HTTP/1.1 404 Not Found.

Is there any way to return the right Status Code using .htaccess or HTML? or any workaround, without using javascript or php?

asked 20 Jun '11, 11:07

joe di castro
113
accept rate: 0%

edited 20 Jun '11, 11:12

nginx should just be forwarding the status code returned from Apache; nginx doesn't modify outgoing responses at all.

Could you show us an example URL where this is happening?

(20 Jun '11, 11:12) David L ♦♦

Sure,

An inexistent page: http://joedicastro.com/noexists.html
Custom error page: http://joedicastro.com/notfound.html

Using

wget -S --spider http://joedicastro.com/noexists.html

We have:

http://joedicastro.com/noexists.html
...
  HTTP/1.1 302 Found
...
http://joedicastro.com/notfound.html
...
  HTTP/1.1 200 OK
(20 Jun '11, 11:18) joe di castro

Both of those are working correctly for me with curl and wget:

$ curl -sI http://joedicastro.com/noexists.html
HTTP/1.1 404 Not Found
Server: nginx

$ curl -sI http://joedicastro.com/notfound.html
HTTP/1.1 200 OK
Server: nginx

$ wget -S --spider http://joedicastro.com/noexists.html
...
HTTP/1.1 404 Not Found
Server: nginx

$ wget -S --spider http://joedicastro.com/notfound.html
...
HTTP/1.1 200 OK
Server: nginx

Are you sure you're hitting the right URLs?

(20 Jun '11, 11:27) David L ♦♦

You're right. The problem is solved now.

I had a wrong Apache directive (a lapse, maybe)

ErrorDocument 404 http://joedicastro.com/notfound.html

instead the correct

ErrorDocument 404 /notfound.html
(20 Jun '11, 11:33) joe di castro

Solved, the problem was mine. I was using an absolute ULR instead of a relative in the .htacces directive.

Sorry for the wasted time.

permanent link

answered 20 Jun '11, 11:24

joe di castro
113
accept rate: 0%

edited 20 Jun '11, 11:25

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×225
×186
×75
×22

question asked: 20 Jun '11, 11:07

question was seen: 6,617 times

last updated: 20 Jun '11, 11:33

WEBFACTION
REACH US
SUPPORT
AFFILIATE PROGRAM
LEGAL
© COPYRIGHT 2003-2019 SWARMA LIMITED - WEBFACTION IS A SERVICE OF SWARMA LIMITED
REGISTERED IN ENGLAND AND WALES 5729350 - VAT REGISTRATION NUMBER 877397162
5TH FLOOR, THE OLD VINYL FACTORY, HAYES, UB3 1HA, UNITED KINGDOM