Question

This is my input url

site.com/?product-43049-keep-kids-filet-children-shoe

I want it to redirect into this

site.com/productDetail.php?id=43049

I have already tried the following code but it doesn't work:

RewriteRule ?product-(.*)-(.*) productDetail?id=$1 [NC,QSA,L]
Was it helpful?

Solution

You cannot match query string in RewriteRule you need to use RewriteCond with %{QUERY_STRING} variable:

Try this code:

RewriteCond %{QUERY_STRING} ^product-([0-9]+)- [NC]
RewriteRule ^/?$ /productDetail.php?id=%1 [L,QSA]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top