SEO URL与多个files.php

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

enter image description here

Table products

enter image description here

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.

Have a look at the following example structure:

Start by adding a table "routes" that just contains each possible url, along with a type (and every field that both pages and products have in common). This would also mean you can remove the url column (and the other common columns) from the pages and products table (or perhaps remove the table all together, if no relevant data is left). Something like this:

TABLE routes
id   route     type      name
1    contact   page      Contact
2    acer1     product   Acer 1

Add your main controller, probably index.php, that looks something like this:

<?php
    $url = isset($_GET["url"]) ? $_GET["url"] : 'home';
    // you should probably use prepared statements here, but that is a different topic
    $result = DB::query("SELECT * FROM routes WHERE url='$url'" LIMIT 1);

   if (! $result) {
     // 404
   }

   // any other common logic can go here, like header and stuff
   require_once 'inc/header.php';

   // now load the type specific page
   include $result['type'] . '.php';

   // and continue with the shared logic
   require_once 'inc/footer.php';

Change your .htaccess to send everything to index.php

RewriteRule ^(.*)$ index.php?url=$1 [NC,L] 

Now you only need a single path element and no type in the url. And you could add a page with url home for when no path elements are provided. Plus you have the possibility to still work with deep links 'my/awesome/deep/linked/page', all you have to do as add that url to your routes table. Inventing a new page type would be very easy as well, just add a 'my-new-type.php' file for the custom logic and you are set.

The key is to have a single point of entry into your application, a so called frontcontroller. And keep your code DRY, Don't Repeat Yourself.