Reputation: 446
i have this url:
merchantstore.php?merchant=100&product=208
that i want to convert to:
/merchant-store-name/product-name
where merchant-store-name replace ?merchant=100 and product-name replace &product=208
How do i do that in htacess file.
Upvotes: 0
Views: 168
Reputation: 3692
I'd suggest you to use a PHP-based approach. In the .htaccess:
RewriteRule (.*) switchboard.php?orig_uri=$1
This captures the entire requested uri, and kind of forwards it to a central switchboard. Then in the switchboard.php you have access to the requested uri, which you can explode() along '/' signs, then look up the id-s associated with the names in you database.
$components = explode('/', $_GET['orig_uri']);
list( $merchant_name, $product_name ) = $components;
// get merchant id and product id from your database
// and serve suitable content by include-ing:
include 'merchant.php';
This is a simple method, and rather easy to scale. It also has the added advantage that no mod-rewrite magic is required.
Don't forget to add proper error-handling.
Upvotes: 1