2

I am trying to rewrite this url: http://www.sample.com/product_guide&product_name=waht&product_type=dog-clipper
to:
http://www.sample.com/waht/dog-clipper

I am using this htaccess code:

 RewriteCond %{QUERY_STRING} ^product_guide&product_name=(.*)&product_type=(.*)$  
 RewriteRule ^$ %1/%2? [R=301, L]

But it doesn't work. Please help me.

2
  • 1
    Wait, which do you want your end user to see & use? Typically that would be the http://www.sample.com/waht/dog-clipper, and you have your rewrite backwards. Commented Mar 22, 2012 at 2:54
  • I want users to see http://www.sample.com/waht/dog-clipper and not the dynamic counter part. Commented Mar 22, 2012 at 3:24

1 Answer 1

3

If you want users to access http://www.sample.com/waht/dog-clipper, you have your rewrites backward. You need to match that URL and rewrite it to the appropriate query string:

RewriteEngine On
# Don't match real existing files so CSS, scripts, images aren't rewritten
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d

# Match the first two groups before / and send them to the query string
RewriteRule ^([^/]+)/([^/]+) product_guide?product_name=$1&product_type=$2 [L]
Sign up to request clarification or add additional context in comments.

2 Comments

I can't get it work. I'm using this htaccess tester http://htaccess.madewithlove.be/
@jaysonatic It will work - the htaccess tester just doesn't cannot process the REQUEST_FILENAME conditions. Comment them out when testing and it will work correctly, but add them back in when you put this into production.

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.