I have a quick question about using mod_rewrite. I've been reading up on it for the last few days and I was wondering what the proper approach would be for my situation. I have URLs that look like this: http://www.example.com/directory/index.php?product=212 I want them to look like this: http://www.example.com/212/Product Name Now my page gets gets the variable "product" out of the URL and pulls information for that record from a database. Do I have to have a rewrite rule for every single product I have? OR... is there a way that I can have mod_rewrite only use the product number part of the URL and ignore anything else? So that I can write "/212/and anything i want here" ? Any help would be great!
Hi, try putting this in your .htaccess file. Pattern: ([0-9]+)/ will match a bunch of numbers followed by a forward slash. .* will match anything Substitution: directory/index.php?product=$1 $1 is replaced with the numbers matched in the pattern between the ( )
Thanks fightrsi! That was exactly what I was looking for! Do you know if I would be able to use those URLs in my sitemap without any search bots throwing a fit about it? Thank again,
You're welcome. Yes, you can use the rewritten URL for your sitemap and anywhere else on your website or other people's website without any problems.