简体   繁体   中英

500 instead of 404 and 500 throws 500 itself

I have a site in a subfolder in which I have a .htaccess file which works quite fine, but if the rules dont find anything, it raises a 500 internal server error istead of 404, however I thought I would solve it by adding a 500 Error document, but the 500 Error page (aside from classic 500 message) says:

"Additionally, a 500 Internal Server Error error was encountered while trying to use an ErrorDocument to handle the request."

So I have a two questions:

  1. Why is 500 raised instead of 404?
  2. What is causing the "additional" error while handling 500 Error document?

This is my .htaccess so far:

DirectorySlash On

RewriteEngine On
RewriteBase /mysubdir/

ErrorDocument 404 /mysubdir/404.php
ErrorDocument 500 /mysubdir/500.php

RewriteRule ^folderexcludedone(/|$) - [NC,L]
RewriteRule ^folderexcludedtwo(/|$) - [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ $1/ [L,R]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/?$ $1.php [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]*)/?$ $1.php?$1=$2 [L,QSA]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/([^/]*)/?$ $1.php?$2=$3 [L,QSA]

Try these rules:

DirectorySlash On

RewriteEngine On
RewriteBase /mysubdir/

ErrorDocument 404 /mysubdir/404.php

RewriteRule ^(folderexcludedone|folderexcludedtwo)(/|$) - [NC,L]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([^/.]+)$ $1/ [L,R]

RewriteCond %{REQUEST_FILENAME} -f [OR]
RewriteCond %{REQUEST_FILENAME} -d [OR]
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteRule ^ - [L]

RewriteRule ^([^/]+)/?$ $1.php [L,QSA]

RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?$1=$2 [L,QSA]

RewriteRule ^([^/]+)/([^/]+)/([^/]+)/?$ $1.php?$2=$3 [L,QSA]

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM