Forum Moderators: phranque

Message Too Old, No Replies

Redirect ? to /

?utm_source=twitterfeed&utm_medium=pingfm to /

         

walkman

6:45 pm on Mar 24, 2011 (gmt 0)



I have quite a few of [www*mydomain.com...] links coming in. I have blocked Google from indexing anything with ? to avoid the dreaded dupes but I'd rather get whatever link juice--if any--so I am trying to redirect /product-keyword?utm_source=twitterfeed&utm_medium=pingfm to just /product-keyword automatically.

I have this on my apache but I can't figure out how to make the product as a variable, since they keyword is the same.

RewriteEngine On
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php?\ HTTP/ [NC]
RewriteRule ^(.*)index.php?$ [www*mydomain.com$1...] [R=301,L]

Any suggestions? Thanks in advance.

g1smd

12:47 am on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Use example.com to stop forum auto-linking.

In your existing rule:

Escape literal periods in patterns.
Replace
.*
with
([^/]+/)*

Replace
(.*)
with
(([^/]+/)*)


You need an extra rule:

RewriteCond %{QUERY_STRING} utm_source=twitterfeed&utm_medium=pingfm
RewriteRule (.*) http://www.example.com/$1? [R=301,L]

Mark Wallace

3:23 pm on Mar 25, 2011 (gmt 0)

10+ Year Member



Hi, I'm looking for a similar redirect.

In my case I'm just trying to redirect any incoming link with a question mark in the url to my domain name.

It's a html website that has no search function and I have quite a few incoming links with queries that simply return my homepage content.

Thank you.

g1smd

9:52 pm on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



What code have you tried so far?

The RewriteRule pattern sees only the "path" part of the URL request.

QUERY_STRING sees only the parameter data after the question mark.

walkman

11:04 pm on Mar 25, 2011 (gmt 0)



g1smd,
thank you! Worked like a charm.

What does this part do though?

Replace .* with ([^/]+/)*
Replace (.*) with (([^/]+/)*)

g1smd

11:49 pm on Mar 25, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



.*
matches to the very end of the string, then has to "back off and retry" hundreds of times to find a match.

([^/]+/)*
looks for "not a slash" "followed by slash" with the whole repeated zero or more times. It therefore matches any level of folder depth, and does so very efficiently.