开发者

url assistance while web development using php

开发者 https://www.devze.com 2023-03-10 21:40 出处:网络
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></l

I have categories saved in databse, ex.

    Category 1
    Category 2
             .
             .
    Category 10

url assistance while web development using php

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消