The question is published on by Tutorial Guruji team.
Been struggling with this problem for a while now and I just can’t het my brain to understand it.
I have a very simple website where I can add items in a database. There is a list on index.php where the list is displayed and each item needs a url that directs to a “more information” page.
The “more information” page has to be a dynamic one as there are a lot of items and these items can be added or deletend.
What my code for this section looks like at the moment:
$result_set = mysql_query("SELECT id, name FROM items WHERE id = $item"); while ($item = mysql_fetch_row($result_set)) { $name = $item['name']; echo "<a href="/items/".$item['1'].".html">$name</a>";
This results in a link if item 1 = wrench ../items/wrench.html.
But this page obviously doesn’t excist. How can I get this to work?
Answer
use .htaccess for this. you can add this code
RewriteEngine On RewriteRule ^items/(.+)$ items.php?page=$1
In your items.php use $items=$_GET[page]; so you can read what is in url after items/
This is a link where you can find more about RewriteRule’s http://httpd.apache.org/docs/current/rewrite/intro.html