I think my question is quite simple but I've been banging my head against the wall for the past few hours.
I have my website using rewriterule to ensure messy path names with php variables are now nice and tidy(I've removed [http://www] from my examples because the system thinks I am putting links and won't let me).
So somebody comes to my site at mysite.co.uk/my-product-P1.html the website will know to post mysite.co.uk/product.php?id=1 to the server.
But I also want to tidy it up the other way around. If an old customer or an old link uses the pathname mysite.co.uk/product.php?id=1 then I want it to return mysite.co.uk/my-product-P1.html instead even though the old pathname will actually still work. I don't want customers accessing the same page from different pathnames.
How do I do this and will it create a loop? On another website I have it working using:
RewriteCond %{QUERY_STRING} ^id=1$ [NC]
RewriteRule ^product\.php$ product-P1.html? [R=301,L]
But on that site there are only around 10 products so I'm able to write these lines for each products. On my other site I have hundreds of products so this isn't practical and I need to do it automatically.
Hopefully this makes sense. I have read through other posts and can't find my solution so apologies if this is clearly explained somewhere else.