Friendly URL in php

0

I need help with this problem, I have the following code

<?php
include 'modules/head.php';
/**Contenido de pagina */
$rutas = array();

if(isset($_GET["ruta"])){
    $rutas = explode("/",$_GET["ruta"]);
    $rutaCategoria = CategoriaController::CtrlCategorias($rutas[0]);
    if($rutas[0]==$rutaCategoria){
        echo 'pagina categoria';
    }else{
        include 'modules/404page.php';
        echo $rutaCategoria;
    }
}
if (isset($_GET["ruta"])==false) {
    include 'modules/inicio.php';
}

/**Fin de contenido de pagina */

include 'modules/footer.php';
?>

where $ routes only takes the first parameter to look for it in a white list of categories that comes from a controller that brings it from a database.

I could use another conditional for the detail of each product but I would stay in the first parameter, as I could keep the first parameter and take the second parameter for the product detail in such a way that when entering a product the url would look like this:

  

domain.com/category/product

obviously each product in the database has a category assigned to it.

my .htaccess has this configuration:

# impedir que se pueda ver el listado de contenidos de un directorio

Options All -Indexes

# url amigables

RewriteEngine On

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^([-a-zA-Z0-9]+)$ index.php?ruta=$1
    
asked by ragnamex 03.01.2019 в 17:58
source

1 answer

0

In your htaccess you collect two variables instead of one

RewriteRule ^([-a-zA-Z0-9]+)/([-a-zA-Z0-9]+)$ index.php?ruta=$1&prod=$2

And you process the second variable to obtain the product.

    
answered by 03.01.2019 в 22:31