notfound.html is not found

冷暖自知 提交于 2019-12-07 07:09:03

问题


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.


回答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.



来源:https://stackoverflow.com/questions/9281381/notfound-html-is-not-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!