Forum Moderators: phranque
We need to do 2 things.
I need to be able to come up with a formula that is idiot proof so I can take a site like:
www.example.com/p=products&category=hats&style=cowboy
and make it read
www.example.com/products/hats/cowboy.html
I know how to make the HTACCESS Process the url buy using:
RewriteRule ^([^/]*)/([^/]*)/([^/]*)\.html$ /?p=$1&category=$2&style=$3 [L]
But i need to redirect it from googles index to redirect it to the SEO friendly URL.
So when a visitor comes from google it redirects to the better url.
THIS DOES NOT WORK
redirect 301 /?p=products&category=hats&style=cowboy www.example.com/products/hats/cowboy.html
([^/]*) allows each element to be blank, so a request for example.com///.html will unintentionally match. Use
([^/][b]+[/b]) instead. .
For your redirect, use a RewriteCond to look at the query string and a RewriteRule to do the redirect, using [R=301,L] flags. The redirect should fire only for direct client requests, not as the result of any prior rewrite action. Make sure the redirect works for index.htm and for index.html and for / without index filename.
There's lots of previous examples scattered around this forum.
g1smd understands your situation quite well, based on his previous posts here and the kind of work that he does. The problem here is one of clarity and terminology rather than knowledge.
For more information, see this thread [webmasterworld.com] (and others) in our Apache Forum Library. It describes the three steps required for an end-to-end solution with the desired effect on the SERPs and your site's user experience, and the terminology is quite precise.
Jim
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /productdetail\.php\?ID=7544&Hash=([^&]+)\ HTTP/
RewriteRule ^productdetail\.php$ http://example.com/7544/whateverIwant.html? [R=301,L]
Works like a charm. Hope that helps someone out there.
[edited by: jdMorgan at 6:43 pm (utc) on Jan. 6, 2010]
[edit reason] example.com [/edit]
However, do you also want the rule to kick in for
id and Id as well as ID? For completeness I would program it to do so, and I would probably do so whether the Hash parameter was even present or not too.
In other words, you would never be able to throw a URL request at the server with any sort of ID parameter included, that would NOT be redirected.