Welcome to WebmasterWorld Guest from

Forum Moderators: Ocean10000 & incrediBILL & phranque

Message Too Old, No Replies

How to REDIRECTMATCH a URL with "?ABC" at the end.

Apache question.



11:55 pm on Aug 25, 2002 (gmt 0)

10+ Year Member

I need to redirect a URL that has ?ABC at the end but the regex in my REDIRECTMATCH directive does not see the ?ABC.
I have tried many including the following:
RedirectMatch (.*)\?ABC$ $1?XYZ
RedirectMatch (.*)ABC$ $1?XYZ
RedirectMatch (.*)?ABC$ $1?XYZ
But no REDIRECTION occurs.
Any ideas?

1. I cannot use REWRITE as Frontpage Extensions are affected.
2. $1?XYZ is not important in this example.
3. Though a newbie at regexs my experiments work as intended UNTIL I add ?anything at the end of a URL.
4. The object of the exercise is to know when a URL has certain 'tracking' information on the end.
5. My URL in question is on many many sites throughout the web so I cannot change it.

I'll give you an example that works WITHOUT the ?ABC.

My intention is to redirect
[mysite.com...] to

by using

RedirectMatch (.*)PageOne.htm$ $1PageTwo.htm

in the .htaccess file within the Test directory.

This works fine, 100%, I just did it now.

However if I want to redirect
[mysite.com...] to


RedirectMatch (.*)PageOne.htm?ABC$ $1PageTwo?XYZ.htm

NO redirection takes place as the PageOne.htm?ABC
is not matched at the end of the string.

No matter how I fiddle with (.*)PageOne.htm?ABC$
I cannot get a match.

As I said originally this is very important for me to resolve as I have an important URL in cyberspace that I urgently need to redirect.




12:18 am on Aug 26, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

Hi Tom.

This is because the ?ABC is now in your environment as the QUERY_STRING. It is not considered part of the URL in the redirect match.

If you're wanting to change the environment, you might consider a combination of redirectMatch (or mod_rewrite) and the SetEnvIf directive.


I've tried to set QUERY_STRING to something else based on certain conditions and the server will not let me modify it. It will let me set my own variables otherwise. Sorry if this caused you to waste some time, but the bottom line is that I don't think you can change ABC to XYZ in the Query String.


12:34 am on Aug 27, 2002 (gmt 0)

10+ Year Member

Hello bobriggs

Thanks for your effort. When I started this exercise I didn't know that ?ABC is not considered part of the URL and so is not parsed.
I also did not know that it was called the QUERY_STRING.

Is it possible, in the .htaccess file to perform an IF...THEN...ELSE.


or something like that.



12:40 am on Aug 27, 2002 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member

No if.then.else stuff (there are some conditionals in mod_rewrite)

I'm a kind of a puzzle person, so I worked on this for quite a while yesterday.

AFAIK, there is only one way: mod_rewite. And then I looked up the problems with FP extensions and so I know what you mean.

I'm glad you asked, though, because I did have a couple of other questions.

Is ?ABC ALWAYS the query? or are there others?

Because this will work:

redirect /Test/PageOne.htm [Test...]

Thereby ignoring the first tracking code.

I'd have to know more about what the circumstances are.

that should read:
redirect /Test/PageOne.htm [mysite.com...]


8:17 am on Aug 27, 2002 (gmt 0)

10+ Year Member

Thank you very much for your efforts. I really appreciate it.

The QUERY-STRING will vary.

So I need to implement different REDIRECTS depending on the QUERY-STRING without using mod_rewrite.



Featured Threads

Hot Threads This Week

Hot Threads This Month