How to use friendly URL?

0

I'm doing my TCC and the theme is SEO, to complete I need to put friendly URL since the current link is like this:

  

post.php? id = 79

Well, I already looked for the .htaccess and managed to leave the main pages (blog.php, contato.php, index.php and sobremim.php) friendly but the ones that are the posts and are recovered from the bank I can not, I would like help.

.htaccess code:

 <IfModule mod_rewrite.c>
  RewriteEngine On

  RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

  RewriteRule ^contato/?$ contato.php [NC,L]
  RewriteRule ^blog/?$ blog.php [NC,L]
  RewriteRule ^sobremim/?$ sobremim.php [NC,L]
  RewriteRule ^inicio/?$ index.php [NC,L]


</IfModule>

Schedule you are looking for at the bank:

<?php 
$mysql = new BancodeDados();
$mysql->conecta();

$ident = $_GET['id'];

//$query = mysqli_query($mysql->con,"select * from postagens where id = $ident");

$query = "SELECT * from postagens where id = $ident";

// executa a query e 'grava' o resultado em $res
$res = mysql_query($query) or die(mysql_error());

// busca os campos da query
$campo = mysql_fetch_array($res);
// armazena cada campo do banco em uma variável
$tit = $campo["titulo"];
$subt = $campo["subtitulo"];
$textinho = $campo["conteudo"];
$imge = $campo["foto"];

$categ = $campo["categoria"];   

?>

<img class="card-img-top" src="admin/img/<?php echo $imge;?>">
   <div class="card-body">
   <h1><?php echo $tit ;?></h1>
   <h2><?php echo $subt ;?></h2>
   <p class="card-text"><?php echo $textinho ;?></p>
   </div>
   <br><br>
   <hr>
    
asked by anonymous 23.09.2018 / 03:39

1 answer

1

Hello, Julia! Welcome! I usually use a friendly URL generator. link

Original URL:

http://www.qualquercoisa.com/postagem.php?id=79

Friendly URL:

http://www.qualquercoisa.com/id/79/

.htaccess rule:

RewriteEngine On

RewriteRule ^id/([^/]*)/$ /postagem.php?id=$1 [L]
    
23.09.2018 / 10:54