0

What do I need to add to my .htaccess file so that I can get pretty URLs?

Currently, I have this two-line of code in my .htaccess file

Options +Multiviews
DefaultType applications/x-httpd-php
RewriteCond %{REQUEST_FILENAME}.php !-f
RewriteCond %{REQUEST_FILENAME}.php !-d
RewriteRule ^(.*)$ index.php?url=$1 
RewriteRule ^single-blog/([0-9]+) single-blog?id=$1

Well, this code allows me stay in the page single-blog but, I am fetching data with the same id that I receive from URL.

My function to receive data from the id received from URL is like this:

function getSingleRow($table, $row_id){
    global $conn;
    $sql  = "SELECT * FROM ".$table." WHERE id = ".$row_id;
    $query = mysqli_query($conn, $sql);
    if(mysqli_num_rows($query) <= 0){
        return false;
    } else {
        $data = mysqli_fetch_assoc($query);
        return $data;
    }
}

So, when I used the single-blog/12 as URL the page throws multiple errors.

  • Post [mcve] to get help. – rmalviya Dec 23 '18 at 06:03
  • What relation does **example.com/single-blog?id=38** have with **example.com/what-we-do/climate/causes-of-global-warming**? – NewToJS Dec 23 '18 at 06:06
  • Both are from post page but I want the URL to be like example.com/single-blog/what-we-do/climate/causes-of-global-warming because I don't want to display the id in the URL. –  Dec 23 '18 at 06:10

1 Answers1

-1

Simply you can store slug as a unique key and query by the slug.