4

Pretty sure based on various examples (like the one here) I set things up correctly:

1) I created a file 'notfound.html' in the root directory of my site

2) I'm running xampp, ie. Apache web server, so based on the stuff I've read, Apache looks for a notfound.html in the root directory of a site when a non-existent page is typed in the browser, such as www.mysite.com/NotAValidPage.html and uses that notfound.html for the 404 error message

Here's what I've tried and the result of each attempt:

1test) I put my own notfound.html in my site's root directory and enter a non-existent page

1result) my notfound.html is not used, but instead the default 404 error from (I guess) my web server, appears and says:

 Object not found!

      The requested URL was not found on this server. If you entered the URL manually please check your spelling and try 
       again.

If you think this is a server error, please contact the webmaster.

Error 404
localhost
2/14/2012 9:11:29 AM
Apache/2.2.17 (Win32) mod_ssl/2.2.17 OpenSSL/0.9.8o PHP/5.3.4 mod_perl/2.0.4 Perl/v5.10.1 

2test) I next added an .htaccess file to the root folder of my site and added this line in this .htaccess file:

    ErrorDocument 404 /notfound.html

then I typed a non-existent page into my browser.

2result) I still see a default 404 error page, not my notfound.html, only this time the default error page says:

 Not Found

 The requested URL /mysite.com/indsadfaex.php was not found on this server.

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

3test) I then modified my .htaccess file by removing the '/' before the name of my custom 404 error page filename as follows: ErrorDocument 404 notfound.html

3result) Now when I type my site name followed by a non-existent page, I no longer see the default 404 error page -- the browser window is completely blank except for the following at the top left corner:

    notfound.html

Not sure what to do here, seems like I am missing some subtlety -- any ideas are really appreciated.

EDIT: I doubt it matters but there are 2 other statements in my .htaccess file for redirection situations:

  RewriteEngine on
  RewriteRule ^([^/\.]+)$ theHandlerPage.php?theArgumentPassedIn=$1 [L]

The regex here simply says 'go to the very end of the URL typed in and match a contiguous string of characters iff no '/' or '.' is in that contiguous stream of characters, then pass those in by way of $_GET[theArgumentPassedIn'] to the file theHandlerPage.php.

I don't think this rewrite rule is coming into play here because it will not match on a bad page name such as mysite/badpage.html because of the '.' in badpage.html.


Okay -- I discovered a bit of unexpectedness.

1) I move my notfound.html error file to the parent directory of my site -- whereas before the file was located at c:/xampp/htdocs/mysite/notfound.html, I have now moved this file to c:/xampp/htdocs/notfound.html.

2) then I use ErrorDocument 404 /notfound.html inside of my .htaccess file, which is located at c:/xampp/htdocs/mysite/.htaccess

And now when I type in the browser bar mysite/aBadfilename.html, my 404 notfound.html is showing up fine.

BUT THIS IS UNWORKABLE. I cannot have my notfound.html reside in the parent directory of my site, because I need a different notfound.html for each site I develop. I must be able to put my site's notfound.html in its folder space, ie. inside c:/xampp/htdocs/mysite.

Because c:/xampp/htdocs is the root folder of all web sites on the server.

Why is my web server looking for my-site's notfound.html in the c:/xampp/htdocs root directory instead of c:/xampp/htdocs/mysite? After all, I type mysite/badfile.html so the web server (in my opinion) should understand that notfound.html is in the c:/xampp/htdocs/mysite folder space.

Andrew Barber
  • 39,603
  • 20
  • 94
  • 123
wantTheBest
  • 1,682
  • 4
  • 43
  • 69
  • A rights issue maybe? Is `notfound.html` accessible to Apache? (You definitely need the slash though.) – Pekka Feb 14 '12 at 17:27
  • the file notfound.html is present in the root folder of my site, in the same folder as my site's landing page 'index.php', and I created the notfound.html file in Netbeans, the development environment I use for all my site work, and Netbeans does not stop the Apache web server from accessing .html files created within the Netbeans IDE (otherwise, none of my web pages would ever be accessed by my Apache web server, since I create all of them in my Netbeans IDE). – wantTheBest Feb 14 '12 at 17:32
  • Strange. So you can access `notfound.html` directly in your browser? – Pekka Feb 14 '12 at 17:32
  • Yes I can -- if I enter mysite/notfound.html in the browser it appears fine. – wantTheBest Feb 14 '12 at 17:33
  • Strange. Can you look into the server's error log to find out which file(s) it's trying to access when it's outputting the 404 message? The log should show the full paths. – Pekka Feb 14 '12 at 17:40
  • I checked my error log file at c:/xampp/apache/logs/error.log and it has not been written to at all today, 2/14/2012. I noticed my access.log in the same folder had today's timestamp so the server has modified access.log today, but all it shows is what is typed in the browser URL bar. It does not show where the server looked to satisfy the request, but it does show I typed in some non-existent page names, but that's all. Is there another error log somewhere in xampp? – wantTheBest Feb 14 '12 at 17:55
  • you could search for other `error.log`s in the system... All error.logs that Apache writes to should be mentioned somewhere in the configuration though! – Pekka Feb 14 '12 at 17:59
  • Your result #2 makes me wonder if you have your notfound.html in a "mysite" subdirectory; Are you sure you have the file in the `DocumentRoot` and not the "mysite" subdirectory under that? – evil otto Feb 14 '12 at 18:00
  • Yes -- the site's root is c:/xampp/htdocs/mysite. That's where my landing page, index.php, is located. That's also where my .htaccess file is located. And that is where my notfound.html file is located. – wantTheBest Feb 14 '12 at 18:04
  • The only error.log is the one above, in c:/xampp/apache/logs/error.log. Although there are other error log files, such as error_log.php and mysql_error.log, a search of the entire c:/xampp folder space showed none of them have been updated in months or years. – wantTheBest Feb 14 '12 at 18:09
  • I've found [the solution to your problem](http://stackoverflow.com/questions/3397868/custom-404-error-htaccess/3400114#3400114) in another thread. Hope it'll help! – inwpitrust May 13 '12 at 12:59

1 Answers1

1

Are you using Virtual Hosts ?
if so, i think there is a problem, open your httpd-vhosts.conf and look for a line where is DocumentRoot C:/xampp/htdocs/bla/blah/mysite/ and write down full path to a host, if it doesn't work play with Directory path. Hope it helps.

Chandra Sekhar
  • 16,256
  • 10
  • 67
  • 90
ignas
  • 11
  • 1