ErrorDocument 404 /404.php
RewriteEngine on
# c www на без
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# на главной index.php index -> 301
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^(|.*/)index /$1 [R=301,L,NC]
#Убирает множественные слэши в середине url
RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]
# .php -> 404
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php - [R=404,L]
# Убирает / на конце url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteCond %{DOCUMENT_ROOT}/$1.php -f
RewriteRule ^([^.]+)$ /$1.php [L]

RewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L] , то конечный файл начинает отображаться. ---> site.ru/9-class/algebra/makarichev/otvet-1 , bertal выдает:HTTP/1.1 200 OK
Server: nginx-reuseport/1.13.4
Date: Fri, 04 Jun 2021 09:46:05 GMT
Content-Type: text/html
Connection: keep-alive
Keep-Alive: timeout=30
Vary: Accept-Encoding
X-Powered-By: PHP/7.3.20HTTP/1.1 404 Not Found
Server: nginx-reuseport/1.13.4
Date: Fri, 04 Jun 2021 09:49:34 GMT
Content-Type: text/html; charset=iso-8859-1
Content-Length: 433
Connection: keep-alive
Keep-Alive: timeout=30
Vary: Accept-EncodingRewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L] все становиться наоборот...

ErrorDocument 404 /error.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index / [R=301,L,NC]
RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L]# 1) C www на без
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
# 3) Убирает множественные слэши в середине url
RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]
# 4) .php -> 404
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php - [R=404,L]RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index / [R=301,L,NC]RewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L]# Убирает / на конце url
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]ErrorDocument 404 /error.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index / [R=301,L]
RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php - [R=404,L]
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
RewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L]ErrorDocument 404 /error.php
RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index|/$ / [R=301,L]
RewriteCond %{THE_REQUEST} ^[^?]+//
RewriteRule ^(.*)$ /$1 [R=301,L]
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule \.php - [R=404,L]
RewriteRule ^([^.]+)$ %{REQUEST_URI}.php [L]HTTP/1.1 404 Not Found
Server: nginx-reuseport/1.13.4
Date: Sun, 25 Apr 2021 17:06:53 GMT
Content-Type: text/html
Content-Length: 936
Connection: keep-alive
Keep-Alive: timeout=30
Vary: Accept-Encoding
X-Powered-By: PHP/5.6.40ErrorDocument 404 /error.php
RewriteEngine on
#Редирект с www на без
RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
RewriteRule ^(.*)$ https://%1/$1 [R=301,L]
#Убирает слэш в конце
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)/$ /$1 [R=301,L]
# Если index. php, php -> 404
RewriteCond %{ENV:REDIRECT_STATUS} ^$
RewriteRule ^index$|\.php - [L,R=404]
RewriteRule ^([^.?]+)$ %{REQUEST_URI}.php [L]