RewriteRule and "?" in filename issue

Discussion in 'General' started by Krzysztof Cuber, May 29, 2014.

  1. Krzysztof Cuber

    Krzysztof Cuber New Member

    Hello,

    I can't make some RewriteRule.

    This is a example from Zend Framework that works on Apache 2.2 and 2.4 - On LiteSpeed doesn't

    Code:
    RewriteEngine On
    
    RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
    RewriteRule ^/*$ cache/index.html [L]
    
    RewriteCond %{DOCUMENT_ROOT}/cache/%{REQUEST_URI}.(html|xml|json|opml|svg) -f
    RewriteRule .* cache/%{REQUEST_URI}.%1 [L]
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    
    RewriteRule ^.*$ index.php [NC,L]
    
    So after few hour i make this:

    Code:
    RewriteEngine On
    
    RewriteCond %{REQUEST_METHOD} GET
    RewriteCond %{DOCUMENT_ROOT}/cache/index.html -f
    RewriteRule ^/*$ cache/index.html [L]
    
    RewriteCond %{REQUEST_METHOD} GET
    RewriteCond %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html -f
    RewriteRule ^.*$ %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html [L]
    
    RewriteCond %{REQUEST_METHOD} GET
    RewriteCond %{QUERY_STRING} ^$
    RewriteCond %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}\.html -f
    RewriteRule ^.*$ cache/%{CURRENT_URI}\.html [L]
    
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    
    RewriteRule ^.*$ index.php [NC,L]
    

    But this doesn't work:

    Code:
    RewriteCond %{REQUEST_METHOD} GET
    RewriteCond %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html -f
    RewriteRule ^.*$ %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html [L]
    This line check that file exist successfully (/cache/example.html?xxx=111.html)
    Code:
    RewriteCond %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html -f
    This one make redirect not to file, but goes forward: (there is nothing notice about file not exist in LOG file)
    Code:
    RewriteRule ^.*$ %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html [L]
    But if I change "?" for any other char like , "-", "_" etc. everything works fine.

    Summary
    If i execute: www.example.com/examle.html?xxx=zzz should be Rewrited to file /cache/examle.html?xxx=zzz.html -> this doesnt work

    But if i make rule to: www.example.com/examle.html?xxx=zzz should be Rewrited to file /cache/examle.html_xxx=zzz.html -> this is works

    This cond return true:
    Code:
    RewriteCond %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html -f
    But this rule not redirect to file:
    Code:
    RewriteRule ^.*$ %{DOCUMENT_ROOT}/cache/%{CURRENT_URI}?%{QUERY_STRING}\.html [L]


    Is there anybody can help me?
    Last edited: May 29, 2014
  2. NiteWave

    NiteWave Administrator

    question mark("?") has special meaning in rewriterule
    not sure use \? instead of ? will work.

    also '/cached/' in first rewriterule example and '/cache/' in rest examples. assume it's in purpose and not typo.
  3. Krzysztof Cuber

    Krzysztof Cuber New Member

    Thank you for your reply.

    Unfortunetly not works. I try [QSA] and \?.

    the name of folder should be "cache". I correct this in first post
  4. mistwang

    mistwang LiteSpeed Staff

    You should avoid using "?" in the rewrite target if it is not intended for query string part, it will definitely break Apache rewrite engine as well. According to the spec.
    If you have to, you can try URL encode it with "%3f".

Share This Page