I have many hours trying to find the solution here but none looks like what I'm looking for ... I will give a long explanation and possibly someone will serve you what I have and not need to change it.
Table pages
Table products
File .htaccess
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^/]+)/([^/]+)/?$ $1.php?route=$1&url=$2 [NC,L]
If I put in the browser: example.com/pages/contact
really we are in: example.com/pages.php?route=pages&url=contact
In the file pages.php
<?php require_once 'inc/header.php'; ?>
<section>
<div class="container">
<div class="row">
<?php
$route= $_GET["route"];
$url = $_GET["url"];
$results = DB::query("SELECT * FROM $route WHERE url='$url'");
foreach ($results as $row) { ?>
<div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
<h2><?php echo $row['name']; ?></h2>
</div>
<?php } ?>
</div>
</div>
</section>
<?php require_once 'inc/footer.php'; ?>
The same goes for products.php
, is the same code as all get by _GET
The problem I have:
I want to eliminate the $route
in the URL, I want the URL looks like this:
example.com/contact
or example.com/acer-one
Is how to do this, if the two designs are identical, ie, put everything in index.php
, the problem is I need to use the two files to display a design or another.
Where do I begin? I modified it? It is a project I'm starting from scratch, so I can change anything.