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:
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”
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!
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.
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.
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).