0

Такой вопрос. На сайте в .htaccess прописано стандартное правило для редиректа с несуществующих страниц на страничку 404.html вида:

ErrorDocument 404 http://mysite.com/404.html

Переадресация работает корректно для всех видов страниц, кроме тех, которые имеют расширение .php.

Т.е., если ввести в браузере http://mysite.com/noexist.html или http://mysite.com/noexist, то редирект работает как надо, но, если ввести ссылку вида http://mysite.com/noexist.php, то сервер просто выводит надпись "File Not Found".

Подскажите, есть ли возможность как-то настроить это дело в .htaccess?

Вот содержимое файла (заменил название сайта на mysite.com и названия страниц на page.html и page.php):

ErrorDocument 404 http://mysite.com/404.html

Options +FollowSymLinks
RewriteEngine On

RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.(php|html|htm)\ HTTP
RewriteRule ^index\.(php|html|htm)$ http://mysite.com/ [R=301,L]

RewriteCond %{HTTP_HOST} ^www.mysite\.com$ [NC]
RewriteRule ^(.*)$ http://mysite.com/$1 [R=301,L]

RewriteEngine on
RewriteCond %{HTTPS} !=on [NC]
RewriteRule ^.*$ https://%{SERVER_NAME}%{REQUEST_URI} [R,L]

RewriteRule ^main.min.css$ style.min.php [L]
RewriteRule ^main.min.js$ script.min.php [L]

RewriteRule ^index.html /index.php [R=301,L]
RewriteRule ^page1.html /page1.php [R=301,L]
RewriteRule ^page2.html /page2.php [R=301,L]


<FilesMatch "robots.txt$"> 
RewriteEngine off 
</FilesMatch>

## EXPIRES CACHING ##
<IfModule mod_expires.c>
    ExpiresActive On

    ExpiresByType image/jpg "access 1 year"
    ExpiresByType image/jpeg "access 1 year"
    ExpiresByType image/gif "access 1 year"
    ExpiresByType image/png "access 1 year"
    ExpiresByType text/css "access 6 month"
    ExpiresByType text/html "access 1 month"
    ExpiresByType application/pdf "access 1 month"
    ExpiresByType text/x-javascript "access 1 month"
    ExpiresByType application/x-shockwave-flash "access 1 month"
    ExpiresByType image/x-icon "access 1 year"
    ExpiresDefault "access 6 month"
</IfModule>
## EXPIRES CACHING ##

<IfModule mod_deflate.c>
    AddOutputFilterByType DEFLATE application/javascript
    AddOutputFilterByType DEFLATE application/rss+xml
    AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
    AddOutputFilterByType DEFLATE application/x-font
    AddOutputFilterByType DEFLATE application/x-font-opentype
    AddOutputFilterByType DEFLATE application/x-font-otf
    AddOutputFilterByType DEFLATE application/x-font-truetype
    AddOutputFilterByType DEFLATE application/x-font-ttf
    AddOutputFilterByType DEFLATE application/x-javascript
    AddOutputFilterByType DEFLATE application/xhtml+xml
    AddOutputFilterByType DEFLATE application/xml
    AddOutputFilterByType DEFLATE font/opentype
    AddOutputFilterByType DEFLATE font/otf
    AddOutputFilterByType DEFLATE font/ttf
    AddOutputFilterByType DEFLATE image/svg+xml
    AddOutputFilterByType DEFLATE image/x-icon
    AddOutputFilterByType DEFLATE text/css
    AddOutputFilterByType DEFLATE text/html
    AddOutputFilterByType DEFLATE text/javascript
    AddOutputFilterByType DEFLATE text/plain
    AddOutputFilterByType DEFLATE text/xml

    BrowserMatch ^Mozilla/4 gzip-only-text/html
    BrowserMatch ^Mozilla/4\.0[678] no-gzip
    BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
    Header append Vary User-Agent
</IfModule>
2
  • У Вас случаем нет каких-то надстроек над .php-расширением в .htaccess? Сейчас проверил ErrorDocument 404, для .php оно работает
    – user249284
    8 июл 2021 в 15:55
  • Андрей, добавил код из .htaccess
    – Eraserhead
    8 июл 2021 в 16:10

0

Ваш ответ

By clicking “Отправить ответ”, you agree to our terms of service and acknowledge you have read our privacy policy.

Посмотрите другие вопросы с метками или задайте свой вопрос.