0

I have a PHP script that queries the database with the id specified in the URL:

http://www.example.com/articles.php?id=5

But I want the URL not to have the id in it but the title that's in the same database in another column. So I basically need to have a link that looks like this:

http://www.example.com/articles/title-of-the-fifth-article

and search for this title in the database so I can rewrite the URL in the .htacces file to where it specifies the id.

Solver
  • 51
  • 1
  • 9

1 Answers1

1

This should work:
Add this to the .htaccess file

RewriteEngine On
RewriteRule ^articles/(.*) articles.php?title=$1 [L]

and the following to the articles.php file:

<?php
    echo $_GET['title'];
?> 
Howli
  • 12,291
  • 19
  • 47
  • 72