Redirect if part of querystring matches

New to mod_rewrite? This is a good place to start.

Redirect if part of querystring matches

Postby Crazytje » Wed Oct 28, 2009 7:49 am

I've been trying to get this working.
But with my little experience in mod_rewrite etc this has been a bit of a problem.

What I'm trying to do, when a user goes to:
http://domain.com/app/index.php?Task=Ch ... @email.com

where the email is variable

Redirect that to:
http://domain.com/newapp/

What I thought was correct(but wasn't working):

Code: Select all
RewriteCond %{QUERY_STRING} ^Task=ChangeAccountInfo&AccountEmail=$
RewriteRule ^index\.php$ http://domain.com/newapp/


any help is greatly appreciated
Crazytje
 
Posts: 3
Joined: Wed Oct 28, 2009 7:34 am

Postby richardk » Wed Oct 28, 2009 11:23 am

$ means "the end", so the regular expressions would only match without an email present.
Code: Select all
Options +FollowSymLinks

RewriteEngine On

RewriteCond %{QUERY_STRING} ^(.*&)?Task=ChangeAccountInfo(&.*)?$ [NC]
RewriteCond %{QUERY_STRING} ^(.*&)?AccountEmail=[^&]+(&.*)?$ [NC]
RewriteRule ^(index\.php)?$ http://domain.com/newapp/? [R=301,L]
richardk
 
Posts: 8800
Joined: Wed Dec 21, 2005 7:50 am

Postby Crazytje » Wed Oct 28, 2009 12:16 pm

Thanks, works like a charm!
Crazytje
 
Posts: 3
Joined: Wed Oct 28, 2009 7:34 am


Return to Beginner's Corner

Who is online

Users browsing this forum: No registered users and 31 guests

cron