mod_rewrite and RewriteRule blockade me from add error page
Asked Answered
L

0

2

i have this .htaccess file, but i need to want to have a 404 error page. but when i add ErrorDocument to it i do nothing. if i write localhost:8888/home/somepage-there-not-exist.

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes...
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]
</IfModule>

it's located in the root same with the app and public folder

Ind the public folder there are this too:

<IfModule mod_rewrite.c>
    <IfModule mod_negotiation.c>
        Options -MultiViews
    </IfModule>

    RewriteEngine On

    # Redirect Trailing Slashes If Not A Folder...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)/$ /$1 [L,R=301]

    # Handle Front Controller...
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteRule ^ index.php [L]

    # Handle Authorization Header
    RewriteCond %{HTTP:Authorization} .
    RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]   
</IfModule>

I know the code coveret /something to files request, but when the file not exit it should get a 404 error.

It's from laravel's root .htaccess after some i like some part of the framework, but i wanna make a code block there only is there to make the website secure, and not a framework (don't wanna invent the wheel again). But i still need it to understand urls that way because it make it SEO and open so there no rules are for the URL

So i have student laravel's code and figure out how it works, but this part about 404, 403 and so on.. is so complicated in laravel's and cross so maney files that you don't have a chance to understand the code and find out how laravel know when it's a 404 error.


UPDATE
I have found this ErrorDocument-VS-RewriteRule after what i see i can use

RewriteRule ^(.*)$ - [L,R=404]
ErrorDocument 404 /errors/errors.php

thats kinda works, but not 100%. the ErrorDocument don't work when you are 2 steps in example: localhost/step1/step2 and it also broke it so when the site exist it still show the error page. i have try to set the code over and under the RewriteRule ^(.*)/$ /$1 [L,R=301]


Yes this project is maybe stupid but i do it for lerning

Langelo answered 1/1, 2017 at 13:26 Comment(12)
Put the complete content of the htaccess file in the questionKurbash
it is the full code of my htaccessLangelo
I don't see the ErrorDocument there...Kurbash
i try to put the ErrorDocument in it, and that dosen't help, thats why i askLangelo
Do you know what the current part of the rewrite does? It makes no much sense to use both togetherKurbash
but how to check for 404 error then?Langelo
you didn't answer my questionKurbash
well i don't know so much about it, i'm new to apacheLangelo
Why do you even use this code if you don't understand what it does?Kurbash
because i need the function of it, what i 100% do, i dont knowLangelo
what is "the function of it" that you need?Kurbash
So a "folder" like localhost/home ask for the file home.php but when you type localhost/users/profile it should ask for a file in the folder users after profile.phpLangelo

© 2022 - 2024 — McMap. All rights reserved.