I always recommend using RewriteBase
, this avoids some problems 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);