Status Code - 404

Hi ,

I would like to ask how to return a 404 status code for a 404 page

Example I have website when a user enters the page will be redirected in to

but my 404 is response code is 200 OK

I have added this code to my .htaccess

ErrorDocument 404 /404

How to fix this ? Any help is highly Appreciated !

Umm, why is that a matter of concern in the first place? You need to create a 404.html file and then add the following in htaccess:

ErrorDocument 404 /404.html

There are two ways to do an error page with Apache/.htaccess:

  • You can redirect to an error page, which means the first response will be a 301 redirect to the error page, and the status code of the final URL is whatever the page on that URL returns. If you want to return a 404 status code to be returned, you can do that with PHP.
  • You can provide a file to use as the error page. If you have this, the server shows the contents of the error page file with a 404 status code. You’re not redirected, which means the URL doesn’t change.

Without your real URL, there is really no way to tell what is going on. Your redirect looks like it might work, but only if you are also stripping the HTML and PHP tags. The article linked below shows some examples for htaccess error pages if you are interested. If you would like further assistance, please provide your URL.

Also, note that WordPress takes care of 404 pages automatically, so if you are using WordPress, that is why.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.