.htaccess error: cant get custom 400,404,500 error page to appear with html and php redirect

.htaccess error: cant get custom 400,404,500 error page to appear with html and php redirect

我的 .htaccess 中有代码应该使用 www.mysite.com/page.html 或 www.mysite.com/page.php 并只显示 www.mysite.com/page。此代码似乎干扰了我重定向到我创建的自定义错误页面的其他代码。我已经在另一台服务器上对其进行了测试,发现我的代码可以单独运行,但不能一起运行。

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ .php
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+).* .html

<-- this is what i added below and it doesnt work with the code abouve, 
however it does work when the only code in the htaccess file-->

ErrorDocument 400 /400.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml

试试这样:

ErrorDocument 400 /400.shtml
ErrorDocument 404 /404.shtml
ErrorDocument 500 /500.shtml

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule ^(.*)$ https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]
...

ErrorDocument 指令应该首先出现。还值得注意的是,您需要错误脚本的绝对路径,例如/home/web/404.shtmlhttp://example.com/404.shtml.