Welcome to WebmasterWorld Guest from 54.158.245.70

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

Basic htaccess query string redirect question

Need a little help redirecting a rogue query string URL

     
6:17 pm on Apr 15, 2011 (gmt 0)

New User

5+ Year Member

joined:Jan 14, 2011
posts: 34
votes: 0


Hi all,

I feel a bit bad for having to ask this but clearly my mod_rewrite skill are a little rusty! I feel like noob!

I have a rogue URL www.mydomain.com/?fr=leihuo.net which I want to redirect to the root domain but I cannot get it to redirect without re-adding the parameter to the end of the URL.

This is what I have at the moment:

RewriteCond %{REQUEST_URI} ^/$
RewriteCond %{QUERY_STRING} ^fr=liehuo.net$
RewriteRule ^$ [mydomain.com...] [R=301,L]

It's just annoying me now so I'm throwing it out to you guys!

Thanks in advance! :-)
6:23 pm on Apr 15, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


First line is redundant.

Escape literal periods.

Allow for other parameters to be in the query string and for the redirect still to happen.

Add a question mark to the target URL to stop query string data being re-added.

RewriteCond %{QUERY_STRING} (^|&)fr=liehuo\.net(&|$)
RewriteRule ^$ http://www.example.com/? [R=301,L]


Use example.com to stop forum auto-linking.
6:29 pm on Apr 15, 2011 (gmt 0)

New User

5+ Year Member

joined:Jan 14, 2011
posts: 34
votes: 0


Legend! Thanks very much and thanks for the explanation. + extra brownie points for the quick response!

Thanks buddy!
6:37 pm on Apr 15, 2011 (gmt 0)

Senior Member

WebmasterWorld Senior Member g1smd is a WebmasterWorld Top Contributor of All Time 10+ Year Member Top Contributors Of The Month

joined:July 3, 2002
posts:18903
votes: 0


Your part is to now study every character in the new ruleset, look at the mod_rewrite documentation and understand exactly how it all works. Every change is important and each one staves off a problem that would have otherwise affected your site months or years in the future.