Created
July 21, 2012 22:56
-
-
Save deivisonarthur/3157491 to your computer and use it in GitHub Desktop.
rewrite op-01
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
dominio.com/ PAGINA / ACAO (funcao) / VAR. DIVERSAS (pode ser id, string, etc..) /VAR. DIVERSAS (pode ser id, string, etc..) /VAR. DIVERSAS (pode ser id, string, etc..) / e por ai vai | |
<IfModule mod_rewrite.c> | |
RewriteEngine On | |
RewriteBase / | |
RewriteCond %{SCRIPT_FILENAME} !-f | |
RewriteCond %{SCRIPT_FILENAME} !-d | |
RewriteCond ^/$ !(\.(gif¦jpg¦css)$¦^/$) | |
RewriteRule ^([a-zA-Z0-9-_]+)?$ index.php?pag=$1 [NC,L] | |
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?pag=$1&func=$2 [NC,L] | |
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?pag=$1&func=$2&id=$3 [NC,L] | |
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?pag=$1&func=$2&id_1=$3&id_2=$4 [NC,L] | |
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?pag=$1&func=$2&id_1=$3&id_2=$4&id_3=$5 [NC,L] | |
RewriteRule ^([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)/([a-zA-Z0-9-_]+)?$ index.php?pag=$1&func=$2&id_1=$3&id_2=$4&id_3=$5&id_4=$6 [NC,L] | |
</IfModule> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
outra solução | |
A melhor solução pra esse caso, é redirecionar tudo pra um index.php, sem regex no .htaccess mesmo, e no próprio PHP fazer o parse da requisição. Algo assim, somente: | |
RewriteEngine On | |
RewriteCond %{REQUEST_FILENAME} !-f | |
RewriteRule ^(.*)$ /index.php [QSA,L] | |
De qualquer forma, uma expressão válida (não otimizada) pra isso seria: | |
Ex.: 'www.test.com/teste/list/limit/10/order/asc/' | |
/[^/]+\/?([^/]+)?\/?([^/]+)?\/?(.*)?\/? index.php?page=$1&action=$2&args=$3 | |
Recebendo "limit/10/order/asc" no index.php e usando um explode pra definir as variáveis e os valores :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment