How to make GET requests without having to use question mark in the URL

Asked

Viewed 279 times

0

I would like to know how I can replace the question marks and ampersand of my URL but still can make GET requests. For example:

i want the url

exemplo.com/perfil.php?usuario=johndoe

turn

exemplo.com/perfil/usuario/johndoe

But in a way that in the profile.php I keep getting to do

$_GET['usuario'];

It may seem to ask a lot, but please explain in detail, as I am not the best person when it comes to programming :/ Thank you

1 answer

-1

Create a file called . htaccess and paste the following code

RewriteEngine On RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-l RewriteRule ^(.*)$ index.php?url=$1 [QSA,L]

Next save this file to the root of your site, very important, if you are doing your site on localhost have to activate the mod_rewrite of Apache

Second step is to manipulate the URL passed in . htaccess

PHP

if(isset($_GET['url'])){
    $url = $_GET['url'];//pega o valor da url
    $open_url = explode('/', $url);//separa a URL depois de cada barra (exemplo: www.meusite.com/artigo/novidades
}

if(isset($open_url[0])){
    $arquivo = $open_url[0];//dá um print_r($open_url) que você vai entender
}elseif(isset($open_url[1])){
    $post = $open_url[1];
}

Here you do the checks of the pages allowed

$diretorio = "pasta";//nome do diretório onde as páginas tem que estar
$paginas = array('pagina1','pagina2');

if(isset($arquivo) && in_array($arquivo, $paginas)){
   include_once("$diretorio/$arquivo.php");
}else{
  include_once("$diretorio/home.php");
}

I’m sorry if you got confused,I answered from the phone, there’s a very basic system of URL AMIGAVEL

Browser other questions tagged

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