I have categories saved in databse, ex.
Category 1
Category 2
.
.
Category 10
Now my menus are,
<ul>
<li><a href="/home/Category_page.php?id=1" >Category name</a></li>
<li><a href="/home/Category_page.php?id=2" >Category name</a></li>
<li><a href="/home/Category_page.php?id=3" >Category name</a></li>
<li><a h开发者_运维问答ref="/home/Category_page.php?id=4" >Category name</a></li>
<li><a href="/home/Category_page.php?id=5" >Category name</a></li>
<li><a href="/home/Category_page.php?id=6" >Category name</a></li>
<ul>
i wanted to do like this
<ul>
<li><a href="/home/Category_name" >Category name</a></li>
<li><a href="/home/Category_name" >Category name</a></li>
<li><a href="/home/Category_name" >Category name</a></li>
<li><a href="/home/Category_name" >Category name</a></li>
<li><a href="/home/Category_name" >Category name</a></li>
<li><a href="/home/Category_name" >Category name</a></li>
<ul>
category names will be different, in href only category name is given, in .htaccess i can redirect to another page,like
Rule in .htaccess:-
RewriteRule ^home/([a-zA-Z0-9_-]+)$ /details.php/$1.php
Here on details page should i check category name in database to fetch details?
or
what are the another options? I don't want category id in url.
If you have a finite number of categories and they don't change very often you could use RewriteMap
to map the names in the pretty handled URLs to the versions with Ids.
http://httpd.apache.org/docs/2.0/mod/mod_rewrite.html#rewritemap
Otherwise you could add a lookup in the database (either a table joined to the category table or a new column in your category table) with a unique column containing the URL friendly category name that you want.
精彩评论