Forum Moderators: phranque
I've been reading in this forum about this, but I am unable to get it to work exactly.
What I want to do it rewrite urls with a? to a url without.
For example:
/product_info.php?products_id=63
to
/product_info.php/products_id/63
This is what I have so far in my .htaccess (from another post on this thread):
RewriteCond %{QUERY_STRING} products_id=([0-9]+)
RewriteRule ^product_info.php product_info.php/products_id/%1 [R=301,L]
This seems to cause an infinite loop. Any ideas?
Welcome to WebmasterWorld!
It causes an infinite loop because you did not clear the query string -- See the "?" I added to the substitution URL.
If you want to clear the query internally, so product_info.php doesn't see it in STDIN, I'd suggest:
RewriteCond %{QUERY_STRING} ^products_id=([0-9]+)$
RewriteRule ^product_info\.php$ /product_info.php/products_id[b]/%1? [L][/b]
RewriteCond %{QUERY_STRING} ^products_id=([0-9]+)$
RewriteRule ^product_info\.php$ http://www.example.com/product_info.php/products_id/%1? [R=301,L]
RewriteRule ^products/product([0-9]+)$ /product_info.php?products_id=$1 [L]
Jim
[edit] Corrected as noted below in msg#4 for future reference. [/edit]
[edited by: jdMorgan at 8:56 pm (utc) on Jan. 8, 2006]
This is SO much help!
I have already changed my real urls to be search engine friendly, so I am just looking to get the old urls out of the search engines with a 301 redirect. So your 2nd code example was perfect (although it took me a minute to figure out to remove the 2nd ) in the RewriteCond statement which I'm sure was a just a typo).
Using these examples I was able to rewrite several other urls that I had been working on to get 301'd too. I am slowly starting to understand how the RewriteCond statement works.
Thanks again man, I owe you a beer or three. :)