Reputation: 57286
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
Upvotes: 0
Views: 1550
Reputation: 143946
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
.
Upvotes: 1