0

Why header('HTTP/1.0 404 Not Found') is not working when I have this line in the .htaccess RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?url=$1 [L,QSA]?

How can I make it work so that I can keep RewriteRule ^([a-zA-Z0-9\-]+)/?$ index.php?url=$1 [L,QSA] - maybe there is a mistake in this line?

Also, even though I remove it, header('HTTP/1.0 404 Not Found') is just showing 404.php on the browrser, instead of pointing to 404.php and displaying the error message in that doc.

Below are my codes and files. They all are in the root dir for test.

index.php,

header('HTTP/1.0 404 Not Found');
exit();

404.php,

echo "<h1>404 Not Found</h1>";
echo "The page that you have requested could not be found.";

.htaccess,

RewriteEngine on

RewriteRule ^([a-zA-Z0-9\-]+)/?$  index.php?url=$1 [L,QSA]

ErrorDocument 404 404.php

Any ideas?

EDIT:

For

ErrorDocument 404 /404.php

I get this error,

The requested URL /mywebsite/xxx/xxx/ was not found on this server.

Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.`

It is still not pointing to 404.php

1 Answer 1

1

If you take a look at the ErrorDocument directive's documentation, it needs either absolute URL-path, so it starts with "/" or "http://" (or "https://"). Otherwise, it interprets the 2nd argument as a message.

It's the same scenario as:

ErrorDocument 404 Wildcard!

And if someone gets a 404 error, they'll see in their browser "Wildcard!".

You need to change it to a URL-path, like /404.php.

Sign up to request clarification or add additional context in comments.

3 Comments

I tried that and I get this The requested URL /mywebsite/xxx/xxx/ was not found on this server. Additionally, a 404 Not Found error was encountered while trying to use an ErrorDocument to handle the request.
@tealou you sure you have the right absolute path? The /404.php can't be relative to where the htaccess file is.
I now just have the problem with getting the right absolute path. any ideas? I just opened a new question - stackoverflow.com/questions/27056404/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.