skip to Main Content

Im facing problem in getting data from mysql db by slug url. When i get data from id it works fine. I substituted urlslug also but no use.

Im trying to change my site article url(s)

mysite.com/public.php?id=12    to    mysite.com/public/google-search

My table:

+----+---------------+---------+------------------------------------+
| id | title         | article |   urlslug  VARCHAR 500 NULL        |
+----+---------------+---------+------------------------------------+
| 12 | google search | xxxxxxx |   google-search                    |
| 13 | bing yahoo    | xxxxxxx |   bing-yahoo                       |
| 14 | friendly seo  | xxxxxxx |   friendly-seo                     |
+-------------------------------------------------------------------+

code to get data by id:

$id = $_GET['id'];
$id = mysqli_real_escape_string($conn,$id);
$query = "SELECT * FROM `table` WHERE `id`='" . $id . "'";
$result = mysqli_query($conn,$query);

while($row = mysqli_fetch_array($result)) {
echo ($row['title']);
echo ($row['article']);    }

Please help. Thanks.

2

Answers


  1. Alright, Here you go

    When a user goes here….

    mysite.com/public/google-search
    

    This rewrite code will change the server side to this

    mysite.com/public.php?id=12
    

    By adding this to your .htaccess file

    RewriteRule ^public/google-search mysite.com/public.php?id=12 [NC]
    

    You would need to do this for all files that you want to mask.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search