Got more questions? Find advice on: ASP | SQL | XML | Windows
in Search
Welcome to RegexAdvice Sign in | Join | Help

Not matching ? as literal

Last post 11-19-2008, 3:52 PM by susb8383. 3 replies.
Sort Posts: Previous Next
  •  11-18-2008, 5:02 PM 48476

    Not matching ? as literal

    Hi,

    I'm pretty new to regex and still trying to figure out how to do simple things.

    Can anyone explain to me why this redirect works in my .htaccess file (I'm on Apache):

    RewriteRule ^([^/]+)\.htmlRD\=123$ test22.php?q=$1 [L]
    when I use the url http://www.mydomain.com/blah.htmlRD=123

    but this redirect gives me a 404 error blah.html not found:

    RewriteRule ^([^/]+)\.html\?RD\=123$ test22.php?q=$1 [L]
    when I use the url http://www.mydomain.com/blah.html?RD=123

    I thought I can use a question mark as a literal if I escape it with \ so I don't understand why the second example doesn't work.

    Thanks.

  •  11-18-2008, 6:01 PM 48477 in reply to 48476

    Re: Not matching ? as literal

    susb8383:

    ...
    RewriteRule ^([^/]+)\.htmlRD\=123$ test22.php?q=$1 [L]
    ...

    I thought I can use a question mark as a literal if I escape it with \ so I don't understand why the second example doesn't work.

    [EDIT: I missed the point entirely in my original response - but I don't seem to be able to delete this comment]

    Susan

     

  •  11-18-2008, 6:11 PM 48479 in reply to 48477

    Re: Not matching ? as literal

    I don't see your original response.
  •  11-19-2008, 3:52 PM 48527 in reply to 48479

    Re: Not matching ? as literal

    Aha, I got my answer.

    Query strings in url redirects are special cases.

    So now this is what I have and it works:
    RewriteRule ^([^/]+)\.html$ test22.php?q=$1 [QSA,L]

    The QSA flag tells it to send through whatever query string it had originally so the end result is that when I put this into the browser:
    http://www.mydomain.com/blah.html?RD=123

    It redirects to this:
    http://www.mydomain.com/test22.php?q=blah&RD=123

View as RSS news feed in XML