D
D
Dmitry Shako2019-07-02 11:56:25
htaccess
Dmitry Shako, 2019-07-02 11:56:25

How to set up a 404 rewriterule response?

Good day to all.
I have a problem with a 404 server response.
The site was created on the basis of one ordered by a friend of mine.
There is a .htaccess file with the following content:

DefaultLanguage ru
AddDefaultCharset utf-8
php_value default_charset "utf-8"
php_value date.timezone "Europe/Moscow"

#AddType application/x-httpd-php .php .phar
RemoveHandler .html .htm
AddType application/x-httpd-php .php .htm .html .phtml .phar


<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /

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



#RewriteCond %{REQUEST_FILENAME} !-f
#RewriteCond %{REQUEST_FILENAME} !-d
#RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.phar))$ [NC]
#RewriteRule (themes\/default)([\d\w\-\/\:\.]*) ${themes/default.phar:$2} [L,QSA]

#RewriteRule ^/tmp/([^\.]+)\.(png|jpg|gif)$    /image.php?file=$1.$2 [NC,L]
RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.jpg|\.jpeg|\.png|\.ico|\.tif))$ [NC]
RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.css|\.js|\.eot|\.svg|\.ttf|\.woff|\.woff2|\.map))$ [NC]
RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.pdf|\.txt|\.html|\.xml))$ [NC]
#RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.phar|\.php))$ [NC]
RewriteCond %{REQUEST_URI} !^([\d\w\-\/\:\.]*(?:\.ogm|\.ogv|\.ogg|\.webm|\.mp4))$ [NC]
RewriteRule . index.php  [L,QSA]
#RewriteRule ^(.*[^/])$ /$1/ [L,R]
 AddType video/ogg .ogm
AddType video/ogg .ogv
AddType video/ogg .ogg
AddType video/webm .webm
AddType video/mp4 .mp4
</IfModule>

AddType image/svg+xml svg svgz
<IfModule mod_deflate.c>
  <IfModule mod_filter.c>
      AddOutputFilterByType DEFLATE "image/svg+xml" \
                                    "text/css" \
                                    "text/html" \
                                    "text/javascript"
  </IfModule>
</IfModule>

there is an index.php file with the following content:
<?php

mb_internal_encoding("UTF-8");


$action = ''; 
$arguments = explode('/', $_SERVER['REQUEST_URI']);
$action = "default";

// function is_mail($email) {
// 	return filter_var($email, FILTER_VALIDATE_EMAIL);
// }

if (count($arguments) > 1) {
  if (!ctype_space($arguments[1]) && !empty($arguments[1])) {
    $action = $arguments[1];
  }
}

if (count($arguments) > 2) {
  $id = $arguments[2];
}

if ($action == "default") {
  $pageTitle = "Дизайн инетерьера в Киеве";
  $pageDesc = "Отличный дизайн интерьера, с учетом Ваших пожеланий, в Киеве по выгодным ценам и в оптимальные сроки от компании Good Idea";
  $pageKeys = "дизайн интерьера киев выгодно ремонт квартир";
  include("index_page.php");
}

else if (strtolower($action) == "sendticket"){
  include("{$_SERVER['DOCUMENT_ROOT']}/sendticket.php");
}

I flipped through a lot of Google pages, but I still didn’t understand how to give me a 404 server response with non-existent pages. I have, in the case of a non-existent page, just a blank page without any code.
There was a redirect to 404.php in the index file. But the problem is that in this case the server gave me the code 200 and showed my page 404.php
Please tell me what you need to register in order to get the server's response code 404, in case of accessing non-existent pages. Thanks

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Ivanov, 2019-07-02
@shakoid

.htaccess404.php

<?php
http_response_code(404);
?>
Страница не найдена

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question