Error Page 404 STANDARD PHP HTACCES

1

Have the following structure in .htaccess:

RewriteEngine On
RewriteRule ^www\/login\/?$ login/ [L,NC,R]
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteCond %{REQUEST_FILENAME}\.php -f 
RewriteRule ^(.*)$ $1.php

ErrorDocument 404 www/errors/404.php

And the following folder structure:

/public_html
  /www - Arquivos como index, editX, deleteX, updateX
    /errors - Dentro tem 404.php, 500.php, 403...

I want any error you give (404) to be inside of www, or outside (in the top folder), type the person type:

1st

  

www.mysite.com / anything that does not exist

or

2nd

  

www.mysite.com/www/there is no such thing as

be redirected to errors / 404.php, and the URL would look like this, ALWAYS:

  

www.mysite.com/www/errors/404

How can I do this, because the way you are neither in 1 nor in the second is redirecting correctly, is simply showing a text:

  

www / errors / 404.php

EDIT

Fixed the error of displaying the text instead of redirecting, but it is not applying the style. The console generates these errors:

GET https://www.meusite.com.br/www/wjhbdsbn 404 (Not Found)
GET https://www.meusite.com.br/assets/css/error.min.css 
GET https://www.meusite.com.br/assets/css/font-awesome.min.css 

My 404.php page:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <base href="https://www.meusite.com.br/" />
    <title>Metta Contabilidade</title>
    <link rel="stylesheet" href="../assets/css/error.min.css" />
    <link rel="stylesheet" href="../assets/css/font-awesome.min.css" />
</head>
<body>
    <div class="container">
        <h1>404</h1>
        <p align="center">Página não encontrada!</p>
        <p align="center">Indica uma dificuldade em encontrar uma página (arquivo ou diretório) especificada na barra de endereço.</p>
    </div><br>
    <div align="center">
        <a href="javascript:history.back()">
           <i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Voltar
        </a><br><br>

        <a href="../main.php">
            <i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Voltar para página inicial      
        </a>
    </div>
</body>
</html>
    
asked by anonymous 13.07.2017 / 17:13

1 answer

5

Redirection error

The routing error occurs because of an error in the .htaccess file. According to documentation , the ErrorDocument directive has the following format:

ErrorDocument <3-digit-code> <action>

Where the value of <action> can be:

  • A local URL, if the value starts with / ;
  • An external URL, if the value is a valid URL;
  • Text to be displayed, if none of the above conditions are satisfied;
  • As you put www/errors/404.php Apache will interpret as text. To fix, just add a slash at the beginning, indicating that it is a local URL:

    ErrorDocument 404 /www/errors/404.php
    

    Error in styles

    CSS styles are not loaded because the path set is wrong. When you use:

    <base href="https://www.meusite.com.br/" />
    

    Along with:

    <link rel="stylesheet" href="../assets/css/error.min.css" />
    

    The file that will attempt to load will be outside the root directory of the application and access to this file would be denied by Apache.

    /var/.../public_html/../assets/css/error.min.css
    

    That is, outside the public_html directory. Since the assets folder is inside the www directory, which in turn is in the root directory, you just have to indicate the absolute path to the file:

    <link rel="stylesheet" href="/www/assets/css/error.min.css" />
    
        
    13.07.2017 / 19:20