Most dynamic sites include variables in their URLs that tell the site
what information to show the user. Typically, this gives URLs like the
following, telling the relevant script on a site to load product number 1.
www.webgagan.com?product.php&product_id=1&category_id=2
We want convert above url to such url
www.webgagan.com/product/1/2/
Simply use below code in .htaccess file
Create product.php page
1) RewriteRule ^([a-zA-Z0-9_-]+)/{0,1}$ $1.php [QSA,L]
From
www.webgagan.com?product.php
To
www.webgagan.com/product/ ->Fire this url
www.webgagan.com/product/ ->Fire this url
2) RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ $1.php?id1=$2 [QSA,L]
From
www.webgagan.com?product.php&product_id=1
To
www.webgagan.com/product/1/ ->Fire this url
www.webgagan.com/product/1/ ->Fire this url
3) RewriteRule ^([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/([a-zA-Z0-9_-]+)/{0,1}$ $1.php?id1=$2& id2=$3 [QSA,L]
From
From
www.webgagan.com?product.php&product_id=1&cate_id=2
To
www.webgagan.com/product/1/2 ->Fire this url
www.webgagan.com/product/1/2 ->Fire this url
If you want echo query string values simply use.
<?php
echo $_GET['id1'];
echo $_GET['id2'];
?>
Good
ReplyDelete