homepage Welcome to WebmasterWorld Guest from 54.235.16.159
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Home / Forums Index / Code, Content, and Presentation / Apache Web Server
Forum Library, Charter, Moderators: Ocean10000 & incrediBILL & phranque

Apache Web Server Forum

    
Basic htaccess query string redirect question
Need a little help redirecting a rogue query string URL
chrisains




msg:4298397
 6:17 pm on Apr 15, 2011 (gmt 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! :-)

 

g1smd




msg:4298404
 6:23 pm on Apr 15, 2011 (gmt 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.

chrisains




msg:4298407
 6:29 pm on Apr 15, 2011 (gmt 0)

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

Thanks buddy!

g1smd




msg:4298414
 6:37 pm on Apr 15, 2011 (gmt 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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / Apache Web Server
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved