Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

ErrorDocument 404 print file name

I have a file index.php, and in the same level a .htaccess with this code:

ErrorDocument 404 index.php

When i generate a not found error is printed a page with the name of the file, so, in this case i only see index.php as literal text. What i want is obviously a redirect to the homepage.

Any idea about this problem?

www\site 
  -index.php
  -.htaccess 
like image 390
anvd Avatar asked Feb 14 '23 20:02

anvd


1 Answers

You want:

ErrorDocument 404 /index.php

In the ErrorDocument docs:

URLs can begin with a slash (/) for local web-paths (relative to the DocumentRoot), or be a full URL which the client can resolve. Alternatively, a message can be provided to be displayed by the browser. Examples:

ErrorDocument 500 http://foo.example.com/cgi-bin/tester
ErrorDocument 404 /cgi-bin/bad_urls.pl
ErrorDocument 401 /subscription_info.html
ErrorDocument 403 "Sorry can't allow you access today" 

So if it's not a FQDN or something that starts with a /, it is assumed that you want a customized message to be displayed.

like image 69
Jon Lin Avatar answered Feb 27 '23 15:02

Jon Lin