Need 301 Redirect help for Dynamic URLs

I want to redirect some dud links (causing duplicate content, not good for SEO) to another link format, which I have set as noindex. I’m just stumped, with the htaccess file syntax.

Here’s what I tried so far - close but no cigar, though. I basically want to take a url like this:

mydomain.com/details.php?gid=29&sgid=&pid=7575

pull the last pid=7575 numbers from it, and then transform it to 301 redirect to this:

mydomain.com/search.php?search=7575

Basically I just need to pull the last numbers as a variable, and insert it into the new url format. Should I be able to use Redirectmatch for this? It’s important that it only does it to links starting with “/details.php”

Thanks in advance.

87,

Did you read the sticky threads OR the tutorial article linked in my signature. If you had, you’d know how to do this as sample code has been included.

Aw, it’s too trivial:

RewriteEngine on
RewriteCond %{QUERY_STRING} &pid=(/d+)
RewriteRule ^details\\.php$ search.php?search=%1 [R=301,L]

The RewriteEngine on ensures that mod_rewrite is not in comment mode, the RewriteCond checks for and captures a digital value for pid (following any other type=value pair) and the RewriteRuUle executes the redirection from details.php to search.php. Easy-peasy!

Regards,

DK

Thanks so much for your reply - I’ll look at those links in your signature.

That syntax you gave me didn’t work, though. I’ve realized that sadly, the script has already been set up with this other line here:

RewriteRule (.*)_g(.*)-(.*)_p(.*).html details.php?gid=$2&pid=$4

Maybe that is why nothing I’ve tried in about 6+ hours screwing around with different syntax is working. Is there any way to rewrite a url like mydomain.com/details.php?gid=29&sgid=&pid=7575 without it affecting this other rewrite rule? I know, it’s ridiculous, but that’s how this stupid script is set up.

RewriteCond %{QUERY_STRING} &pid\\=([^&]+)
RewriteRule ^details\\.php$ http://mydomain.com/search.php?search=%1&match_type=id [R=301,L]

OKAY - so this actually works, I had to forward slash out the = sign to escape it, and then use ([^&]+)

But I guess this still isn’t going to work. It makes all of my other links in the store useless, pushing them over to this same rewrite… which makes no sense to me. I guess the entire script is a rewrite of a rewrite of a rewrite. What a mess.

87,

While I loathe the inappropriate use of (.*), you could put your old code first to pickup the {yadda-yadda}.html and send it to details.php then follow that with my code to pick the pid out of the query string and redirect to search - or your code could work, too, although a pid is normally a numeric value, not a “not-&” string. Your leading & means that there MUST be a previous key/value pair and I’m shocked that your host would require the = to be escaped (but won’t argue with success).

Regards,

DK