Notfound.html not found

Pretty accurately based on various examples (like here ) I correctly installed:

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

2) I run xampp, i.e. The Apache web server, therefore, based on the materials that I read, Apache looks for notfound.html in the root directory of the site when a non-existent page is entered in the browser, for example, www.mysite.com/NotAValidPage. html and uses this notfound.html for 404 error message

Here is what I tried and the result of each attempt:

1test) I put my own notfound.html in the root directory of the site and entered a non-existent page

1result) my notfound.html is not used, but instead a 404 error appears from (in my opinion) my web server and a message appears:

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) . Then I added the .htaccess file to the root folder of my site and added this line to this .htaccess file:

  ErrorDocument 404 /notfound.html 

then I typed a nonexistent page into my browser.

2result) I still see the default 404 error page, and 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) . Then I changed my .htaccess file by removing the '/' in front of the name of my custom 404 error page name as follows: ErrorDocument 404 notfound.html

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

  notfound.html 

Not sure what to do here, it seems that I lack some subtlety - any ideas are really appreciated.

EDIT: I doubt this matters, but there are 2 other redirect operators in my .htaccess file:

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

The regular expression here simply says: "Go to the end of the URL typed and matching a continuous string of characters iff no '/' or '.' is in this continuous stream of characters, and then pass them through $ _GET [theArgumentPassedIn] to theHandlerPage.php file.

I don't think this rewrite rule comes into play here because it will not match the name of the bad page, for example mysite / badpage.html, because of '.' in badpage.html.


Good - I found a little surprise.

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

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

And now, when I type in mysite/aBadfilename.html in the browser line, my 404 notfound.html displays well.

BUT THIS IS NECESSARY. I cannot have my notfound.html in the parent directory of my site, because I need a different notfound.html for each site that I am developing. I should be able to put my site notfound.html in its folder, i.e. inside c:/xampp/htdocs/mysite.

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

Why is my web server looking for my notfound.html site in the root directory c:/xampp/htdocs instead of c:/xampp/htdocs/mysite ? In the end, I type mysite / badfile.html, so the web server (in my opinion) should understand that notfound.html is located in the c:/xampp/htdocs/mysite .

+4
source share
1 answer

Do you use virtual hosts?
if so, I think there is a problem, open your httpd-vhosts.conf and find the line where DocumentRoot C:/xampp/htdocs/bla/blah/mysite/ is located C:/xampp/htdocs/bla/blah/mysite/ and write down the full path to the host if it does not work with directory Directory. Hope this helps.

+1
source

Source: https://habr.com/ru/post/1396444/


All Articles