Internal redirect friendly URL

1

I'm creating an image gallery page with a database, and clicking an image is redirected to the page profile.php with the image data as if it were a profile.

I want to make my URL more beautiful, it is currently appearing like this:

localhost/meusite/profile?slug=nome-da-imagem

I would like to leave this:

localhost/meusite/nome-da-imagem

I'm going to post the structure and part of the code to better understand, it's hard for me to find a solution. The file structure looks like this:

  • MySite
    • css
      • style.css
    • js
      • script.js
    • pages
      • home
      • profile
    • cPanel
      • pages
      • uploads
    • .htaccess
    • config.php
    • index.php

no config.php:

define('INCLUDE_PATH', 'http://localhost/meuSite/');
define('INCLUDE_PATH_PAINEL',INCLUDE_PATH.'painel/');//usei esses 
  INCLUDE_PATH pra nao precisar configurar muito ao passar para o servidor.

define('BASE_DIR_PAINEL',__DIR__.'/painel');

//conexao banco de dados
define('HOST','localhost');
define('USER','root');
define('PASS','');
define('DB','meusite');

index.php: (I will not put all HTML tags to not take up too much space)

   <header>
  <?php 
     $url = isset($_GET['url']) ? $_GET['url'] : 'home';
        if(file_exists('pages/'.$url.'.php')){
           include('pages/'.$url.'.php');
        }else{
           echo 'essa página não existe!';
        }
   ?>

  <footer>
 </footer>

no htaccess:

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

Options -Indexes

in home.php:

<section>
//conexão do banco

<?php

//MySql::banco() = função para conectar no meu banco de dados.

$bd = MySql::Banco()->prepare("SELECT * FROM 'nome_tabela'");

$bd->execute();

$imagens = $bd->fetchAll();

foreach($imagens as $key => $value){

$slug = $value['slug'];

?>


<a href="<?php echo INCLUDE_PATH; ?>profile?slug=<?php echo $slug?>"></a>

<?php }?>

in page profile.php:

<?php

$slug = $_GET['slug'];
if($slug == $slug){
$bd = MySql::Banco()->prepare("SELECT * FROM 'nome_tabela ' WHERE slug = 
?");
$bd->execute(array($slug));
$imagens = $bd->fetchAll();
foreach ($imagens as $key => $value) {
?>


 <h1><?php echo $value['nome_img'];</h1>
 <img scr="<?php INCLUDE_PATH;?>uploads/<?php echo $value['imagem'];?>"
 <?php } ?>
    
asked by anonymous 12.09.2018 / 18:25

0 answers