url rewriting - Friendly URLs htaccess and php

798

hello stackoverflow community hopefully you understand what im trying to do

im working with pretty URLs withhtaccess and php and i have seen in some pages that in the URL appear the title of the news something like...

http://www.samplePage.com/news/killer-shooter-in-new-york

i would like to know how i do that , im not that good in htaccess or friendly URLs but i try to do my best and this is the way that im doing it....

my .htaccess

    Options All -Indexes

    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^([a-zA-Z0-9/]+)$ index.php?view=$1

my html

//after the header label i add this to include the content
     <?php

          if (isset($_GET["view"])) {

          $view=explode("/",$_GET["view"]);

                include"modules/".$view[0]."-view.php";

          }else{

             include"modules/home-view.php";

          }

      ?>

now i got these links that take me to the news

  <ul >
    <?php $sql=$con->query("SELECT * FROM latest_news LIMIT 4"); 

     while ($row=$sql->fetch_array()) { ?>
 //note: the URLSERVER is the route for example http://localhost/projectNews/  
     <li >
      <a href="<?php echo URLSERVER?>news/<?php echo $row['id']?>/"><?php echo $row['post_title']?></a>

     </li>
     <?php } ?>
    </ul>

the ouput of this ishttp://localhost/projectNews/news/4/

once i click the link what i would like to do is to add the title of the new after the id of the news like i explained before for example...

http://localhost/project/news/4/killer-shooter-in-new-york

can someone of you guys help me please? im a little bit of new on this, thanks!

People are also looking for solutions to the problem: php - Lazy loading not possible with DI?

Source

Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.