RewriteRule Errors with ?

Discussion in 'Apache Migration/Compatibility' started by Steven Edwards, Jan 31, 2008.

  1. Steven Edwards

    Steven Edwards New Member

    Hi guys,

    I'm helping a friend set up RewriteRule directives for a site and LiteSpeed doesn't seem to like them. I'm redirecting everything to Google to make sure it's not a box error, then going back to his site.

    The following directives work:

    ---
    RewriteEngine On
    RewriteRule ^([0-9]+) http://www.google.com/$1 [R=301,L]

    //

    RewriteEngine On
    RewriteRule ^test([0-9]+) http://www.google.com/$1 [R=301,L]

    //

    RewriteEngine On
    RewriteRule ^test/([0-9]+) http://www.google.com/$1 [R=301,L]
    ---

    But the following fails:

    ---
    RewriteEngine On
    RewriteRule ^test?([0-9]+) http://www.google.com/$1 [R=301,L]

    //

    RewriteEngine On
    RewriteRule ^test\?([0-9]+) http://www.google.com/$1 [R=301,L]
    ---

    As soon as I add the ? character, LiteSpeed gives me a 404.

    I checked prior threads on Google (site:litespeedtech.com rewriterule), but found none that specifically mentioned this.

    Suggestions?

    Thanks,

    Steven
    Last edited: Jan 31, 2008
  2. mistwang

    mistwang LiteSpeed Staff

    first, "?" is a special character in Regular expression, so you need to escape it with a "\".
    Second, RewriteRule only match the URI part of the URL, query string part will not be matched. You need to add a "RewriteCond ${QUERY_STRING} ..."
  3. Steven Edwards

    Steven Edwards New Member

    Hi Mistwang,

    I forgot to include that I tried escaping the character at first; I was editing my post as you replied to indicate that.

    Thanks for the quick reply. The same directive works perfectly on an Apache server with another hosting company. I'll lookup the RewriteCond directive in the documentation. Would prepending "RewriteCond ${QUERY_STRING}" to the existing directives be enough to fix it?
  4. mistwang

    mistwang LiteSpeed Staff

  5. Steven Edwards

    Steven Edwards New Member

    Thanks a ton. :)

Share This Page