0

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.

4
  • is $1 = merchant-store-name and $2 = product-name ? Commented Aug 15, 2012 at 13:29
  • 1
    You need to be a lot more descriptive. What is $1, $2? What do they map to? Commented Aug 15, 2012 at 13:29
  • Give us an example set of urls (not with placeholders, with some real or close to real values). Commented Aug 15, 2012 at 13:30
  • I Have corrected the question and improved my accepted rate as suggested. Commented Aug 17, 2012 at 10:43

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.