Htaccess is not redirecting to 404 error page

4

I have .htaccess with the following configuration:

ErrorDocument 404 /erro404.html
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteRule ^index/?$ index.php [NC,L]
        RewriteRule ^index/([a-z0-9-]+)?$ index.php?pagina=$1 [NC]

</IfModule>

But it is not redirecting when I type a page that does not exist. What can it be?

    
asked by anonymous 18.01.2015 / 20:27

2 answers

1

I always recommend using RewriteBase , this avoids some problems, in case if index.php is in the root folder:

ErrorDocument 404 /erro404.html

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(index|index/)$ index.php [NC,L]
    RewriteRule ^index/([a-z0-9-]+)$ index.php?pagina=$1 [NC]
</IfModule>

You can also use PATH_INFO instead of GET to get the route:

ErrorDocument 404 /erro404.html

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /
    RewriteRule ^(index|index/)$ index.php [NC,L]
    RewriteRule ^index/([a-z0-9-]+)$ index.php/$1 [NC]
</IfModule>

In PHP instead of using $_GET['pagina'] , use:

<?php
$path = empty($_SERVER['PATH_INFO']) ? NULL : $_SERVER['PATH_INFO'];

var_dump($path);
    
03.07.2015 / 17:29
0

Try putting these commands at the top of .htaccess

RewriteEngine On
RewriteCond %{SCRIPT_FILENAME} !-f
RewriteCond %{SCRIPT_FILENAME} !-d
    
18.01.2015 / 20:36