friendly urls for various folders

Asked

Viewed 794 times

1

I have these urls, I’m using subfolders, but htaccess will be at the root

MEDICAL PASTE

when the person logs in to redirect appears in the url ? id=1 without the index

laudar.php?id=1
relatoriolaudos.php?id=1
listalaudos.php?id=1
imprimir.php?id=1&idlaudo=1
editarlaudo.php?id=1&idlaudo=1
bloqueado.php?id=1&idlaudo=1&idusuario=1&nivelu=1&status=1
editardados.php?id=1

FOLDER LOGIN

index.php
senhaincorreta.php
sair.php
mensagem.php

FOLDER ADMINISTRATOR

when the person logs in to redirect appears in the url ? id=1 without the index

cadastrodemedicos.php?id=1
cadastrodedigitador.php?id=1
cadastroCategoria.php?id=1
cadastrodeexames.php?id=1
cadastrodeadministrador.php?id=1
cadastrodeadministrador.php?id=1



pesquisademedicos.php?id=1
pesquisadedigitador.php?id=1
pesquisaCategoria.php?id=1
pesquisadeexames.php?id=1
pesquisadeadministrador.php?id=1

exibeadmin.php?id=1&idadmin=1
exibemedico.php?id=1&idmedico=1
exibedigitador.php?id=1&iddigitador=1
pesquisaCategoria.php?id=1
exibetipo.php?id=1&idtipo=5


editaradmin.php?id=1&idadmin=1
editarmedico.php?id=1&idmedico=1
editardigitador.php?id=1&iddigitador=1
editarcategoria.php?id=1&idcategoria=2

TYPING FOLDER

when the person logs in to redirect appears in the url ?id=1 without the index

digitando.php?id=2
digitar.php?id=2&idlaudo=4
revisao.php?id=2
imprimir.php?id=2&idlaudo=1
  • You will have to readjust all the files to get.

  • That ? id=1, is the idUsuario? Why not register the id of this user @Déboragonçalves

1 answer

0

You can work your htaccess this way:

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]

Later you can also use $_SERVER['REQUEST_URI'] to search your URL, based on this, work the internal one by one...

And you shall pass the idUsuario for session so that it is not possible to exchange it via URL.

This would be a practical example:

// Recupera a URL da requisição e seus parâmetros, separando em um vetor dividido pelo caracter "/"
$geturl = explode( "/", str_replace( strrchr( $_SERVER["REQUEST_URI"], "?" ), "", $_SERVER["REQUEST_URI"] ) );
array_shift( $geturl );

// Considera o primeiro parâmetro como o arquivo php
$tipo = $geturl[0];

// Se o arquivo existir, inclui na página. Caso contrário, devemos redirecionar o usuário para uma
// tela amigável de error 404
if ( is_file( "$tipo.php" ) )
{
    include "$tipo.php";
}
else
{
    echo "Página não encontrada";   
}

Another option is to take a look at this article: http://php.eduardokraus.com/trabalhando-com-url-amigavel-no-php

Browser other questions tagged

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