I’m new to mod_rewrite and need to do something for my client.
Suppose I have the http://www.mydomain.com/products.php?prod_id=32.
This product has a section (clothes) and a name (shirt). These names and sections are unique.
In a SEO-Friendly Url, it should be http://www.mydomain.com/products/clothes/shirt/.
I know I can create
RewriteRule ^products/([A-Za-z0-9-]+)/([A-Za-z0-9-]+)/?$ products.php?section=$1&name=$2
I can do that, and it works. But I want people who enter http://www.mydomain.com/products.php?prod_id=32 to be redirected to http://www.mydomain.com/products/clothes/shirt/ (changed in the browser itself). How can I do that without inserting the id in my url? Is it possible to call a “pre-processing” php file in my .htaccess, and recreate “products.php?section=$1&name=$2”?
Anyone has a good link with really detailed explanation of mod_rewrite?
Thanks!
You may have a bigger problem than
mod_rewritecan handle gracefully. You can also use PHP to return a redirect to the browser. That way you can access your database to figure out that product_id 32 is /clothes/shirts/