Question mark '?' in the regular expression

Alles, was den Apache betrifft, kann hier besprochen werden.

Question mark '?' in the regular expression

Postby BostX » 29. January 2009 19:21

Hi everyone
It seems like I have a problem with the question mark '?' in the regular expression:
Does anyone know what's the trouble? thx in advance! I have a couple of existing redirects:
Code: Select all
Redirect permanent   /customer_101   https://www.aaa.com/path/index.do?customer=101
Redirect permanent   /customer_102   https://www.aaa.com/path/index.do?customer=102
Redirect permanent   /customer_103   https://www.aaa.com/path/index.do?customer=103
so every customer can access his pages unter both links:
Code: Select all
https://www.aaa.com/path/index.do?customer=10x
https://www.aaa.com/path/customer_10x
and I'd like to redirect both links but only the customer 102. I do:
Code: Select all
Redirect    temp    /customer_102    https://www.bbb.com/game_over.html
and this works as desired. But when I try to redirect the
Code: Select all
https://www.aaa.com/path/index.do?customer=102
I get in troubles. I think I tried every combination:
Code: Select all
RewriteRule    ^/path/index\.do.customer=102$     https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do?customer=102$     https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do\?customer=102$    https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do\?customer\=102$   https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do\?$                https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do?customer\=102$    https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^.*customer=102$                   https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^.*102$                            https://www.bbb.com/game_over.html [R=301,L]
but these rules do not not redirect any link
Code: Select all
RewriteRule    ^/path/index\.do?$                 https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do?.*$               https://www.bbb.com/game_over.html [R=301,L]
RewriteRule    ^/path/index\.do.*$                https://www.bbb.com/game_over.html [R=301,L]
and these rules redirect every link. And I tried the same with:
Code: Select all
Redirect temp          ...
RedirectMatch temp     ...
and it does'nt work anyway :(

BostX
BostX
 
Posts: 2
Joined: 29. January 2009 19:03

Re: Question mark '?' in the regular expression

Postby Nobbie » 29. January 2009 23:34

Question mark has a special meaning in regular expressions, if you want to match a question mark, you have to escape it via backslash.

It might be a good idea to read about the basics of regular expressions.
Nobbie
 
Posts: 8780
Joined: 09. March 2008 13:04

Re: Question mark '?' in the regular expression

Postby BostX » 30. January 2009 15:11

Nobbie wrote:Question mark has a special meaning in regular expressions, if you want to match a question mark, you have to escape it via backslash.
It might be a good idea to read about the basics of regular expressions.

I know that and I did escape the question mark with backslash - but it still doesn't work!
BostX
 
Posts: 2
Joined: 29. January 2009 19:03

Re: Question mark '?' in the regular expression

Postby mzehngut » 02. March 2009 00:21

I just ran into this too. Try [?] instead of \? in your regular expression. This worked for me.
mzehngut
 
Posts: 1
Joined: 02. March 2009 00:19


Return to Apache

Who is online

Users browsing this forum: No registered users and 3 guests