Search code examples
phpmysql.htaccessmod-rewritepermalinks

Permalink, .htaccess pretty urls


I'm really sorry if i'm annoying you guys but this is my final question in regards to .htaccess tricks

I need wordpress style, 'pretty permalinks'

But It's too confusing for me.

I need, this url http://test.com/?page=test&ID=1 to be http://test.com/test/NAMEFROMDATABASE

How? I know how to get ID=1 by using $_GET['ID'], but how do I put a value from the database in the url, and read it?


Solution

  • you can not get ID value by $_GET['ID'] directly from this URL : http://test.com/test/NAMEFROMDATABASE.

    You can get ID by following below logic.

    1. create link by category name. i.e. if you have category laptop then create link like http://test.com/category/CATNAME

    2. Write rewrite code in htaccess.RewriteRule ^category/(.*)$ categories\.php?CNAME=$2&%{QUERY_STRING} [L]

    3. in PHP code get category ID from category name.$catName=$_GET['CNAME']

    OR

    1. create link by category name and category ID. i.e. if you have category laptop then create link like http://test.com/category/CATNAME-ID-CATID
    2. Write rewrite code in htaccess. RewriteRule ^category/(.*)-ID-([0-9]+)$ categories\.php?ID=$2&%{QUERY_STRING} [L]
    3. in PHP code get category ID directly. $catID= $_GET['ID']