Search code examples
regexhttp-redirectzeus

Redirecting urls with query strings using regex


I'm redirecting old urls on a website to new urls on a different website. It's using a Zeus web sever and the first two rules work just fine. However it doesn't seem to play ball with the third url which has a query string in it... Any ideas on how to fix this? Seems as though I might need a regex to deal with the special character ? as it works fine if I take this out of the match. Thanks

match URL into $ with ^/$
if matched
set OUT:Location = http://www.website.co.uk/
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif

match URL into $ with ^/index.php$
if matched
set OUT:Location = http://www.website.co.uk/
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif

match URL into $ with ^/index.php?cPath=1_50$
if matched
set OUT:Location = http://www.website.co.uk/categories.php?category=Boilers
set OUT:Content-Type = text/html
set RESPONSE = 301
set BODY = Moved
goto END
endif

Solution

  • I am not familiar with Zeus url rewriting. But if it's using a standard regular expression you need to escape the ? with a backslash.

    match URL into $ with ^/index.php\?cPath=1_50$
    

    The question mark is normally a metacharacter that modifies the preceding character or expression, making it optional. So your pattern right now will match /index.phpcPath=1_50 or /index.phcPath=1_50.