Error 404 Page PHP STANDARD HTACCES

Asked

Viewed 4,680 times

2

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 that gives (404) either in within www, or out (in the top folder), like the person type:

1st

www.meusite.com.br/anythingThere is no such thing as

or

2nd

www.meusite.com.br/www/otherthere is no

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

www.meusite.com.br/www/errors/404

How could I do that, because the way it is neither in 1 nor in the second is redirecting correctly, is simply showing a text:

www/errors/404.php

EDIT

Fixed error showing text instead of redirecting, but it is not applying the style. In the console these errors are generated:

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 page 404.php:

<!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>
  • Try to put a / before www/errors/404.php. In the documentation says: "A local URL to redirect to (if the action Begins with a "/")".

  • Okay that worked. But my style is not showing, it is showing only the text. It redirects but only shows the text.Could you help me find why? @Andersoncarloswoss

  • Put the absolute URL to the CSS files, not the relative one.

  • Isn’t that what the <base href="meusite.com.br"> does? @Andersoncarloswoss

  • Strip the .. CSS, if the directory is at the root of the project...

  • Not at the root. @Kaduamaral

  • This way it would be accessing CSS files outside the root directory, which makes no sense. Put something like /www/assets/..., or /assets/... if the folder is at the project root.

  • It worked with the first option: /www/Assets/... Thank you so much for helping @Andersoncarloswoss

Show 3 more comments

1 answer

7

Redirect error

Directional error occurs due to an error in the file .htaccess. In accordance with the documentation, the directive ErrorDocument has the following format:

ErrorDocument <3-digit-code> <action>

Where the value of <action> can be:

  1. A local URL if the value starts with /;
  2. An external URL, if the value is a valid URL;
  3. Text to be displayed if neither of the two conditions is met;

How did you put www/errors/404.php Apache will interpret it as text. To fix, simply add a bar at the beginning, indicating 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 you will try to upload will be outside the application’s root directory and access to this file would be denied by Apache.

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

That is, out of the directory public_html. Like the folder assets is inside the directory www, which in turn is in the root directory, just you indicate the absolute path to the file:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.