[Solved] .htaccess problem

Discussion in 'General' started by Cyb3r.ua, Jul 27, 2013.

  1. Cyb3r.ua

    Cyb3r.ua New Member

    Who can tell me why these rules in my .htaccess rules don't work?
    help plz
    # if group_1 missed then redirect 410(Gone) without paramaters
    RewriteCond %{QUERY_STRING} 'group_1=&'
    RewriteRule ^tovary\.php - [R=410,L]

    # replaces all '+'(whitespace) onto '%20' in query string
    ####### loop changing '+' onto '%20'
    RewriteCond %{QUERY_STRING} (.*)\+(.*)
    RewriteRule ^tovary\.php /tovary.php?%1\%20%2 [N,NE,E=PlusWasSubstitutedForHex:1]
    ####### 301 redirect to fix all substituting
    RewriteCond %{ENV:REDIRECT_PlusWasSubstitutedForHex} 1
    RewriteRule ^tovary\.php /tovary.php [NE,R=301,L]

    On (Apache 2.2.17) is OK.
  2. NiteWave

    NiteWave Administrator

    let's test one by one.
    enable rewrite log level 9, my test shows:
    RewriteRule ^tovary\.php - [R=410,L]
    2013-07-27 21:34:00.865 [INFO] [] [REWRITE] Cond: Match 'a=1&group_1=&b=2' with pattern 'group_1=&', result: 1
    2013-07-27 21:34:00.865 [INFO] [] [REWRITE] No substition
    2013-07-27 21:34:00.865 [INFO] [] [REWRITE] Last Rule, stop!
    if change above - to an existing file, it works:
    RewriteRule ^tovary\.php /e.html [R=410,L]
    2013-07-27 21:38:49.154 [INFO] [] [REWRITE] Cond: Match 'a=1&group_1=&b=2' with pattern 'group_1=&', result: 1
    2013-07-27 21:38:49.154 [INFO] [] [REWRITE] Source URI: 'hello.php' => Result URI: '/e.html'
    2013-07-27 21:38:49.154 [INFO] [] [REWRITE] Last Rule, stop!
    will show
    410 Gone
    The requested resource is no longer available at the server and no forwarding address is known.

    in browser.
    per rewrite log, it looks when "-" is used, rewrite flag R=xxx is ignored in litespeed's current implementation, this is a subtle difference.

    in such kind of cases, change your rewrite rule is the quickest way to workaround it
  3. Simon

    Simon Member

    Good day, guys. Help with next rules, please.
    Why does not work it?

    RewriteCond %{QUERY_STRING} 'group_1=%CE%F0%E3%F2%E5%F5%ED%E8%EA%E0&group_2=%D3%ED%E8%F7%F2%EE%E6%E8%F2%E5%EB%E8+%E4%EE%EA%F3%EC%E5%ED%F2%EE%E2'
    RewriteRule ^tovary\.php /shredder.php? [R=301,L] 2)

    # replaces all '+'(whitespace) onto '%20' in query string
    ####### loop changing '+' onto '%20'
    RewriteCond %{QUERY_STRING} (.*)\+(.*)
    RewriteRule ^tovary\.php /_tovary.php?%1\%20%2 [N,NE]
    RewriteCond %{QUERY_STRING} (.*)\+(.*)
    RewriteRule ^_tovary\.php /_tovary.php?%1\%20%2 [N,NE]
    ####### 301 redirect to fix all substituting
    RewriteCond %{QUERY_STRING} !(\+)
    RewriteRule ^_tovary\.php /tovary.php [NE,R=301,L]
  4. webizen

    webizen Well-Known Member

    enable rewrite logging (add 'RewriteLogLevel 9' in httpd.conf) and grep 'REWRITE' in error log to debug.
  5. Simon

    Simon Member

    I'm added in httpd.conf into the section<logging>
    and nothing .
    The rules:

    does not work and nothing to the log spelled.

    For example:
    Do 'tovary.php?pam+param' and not rewrite '+' into %20

    P.S. Sorry for my english.
  6. webizen

    webizen Well-Known Member

    Do not use "<RewriteLogLevel>9</RewriteLogLevel>" but "RewriteLogLevel 9" instead.
  7. Simon

    Simon Member

    Thank you!

    Now I see a lot of errors in the RewriteRules, but none of for the required site.
  8. webizen

    webizen Well-Known Member

    grep your IP (along with REWRITE) while you make request to debug from command line as follows:
  9. Simon

    Simon Member

    So I did. No errors.
    For rule:
    I'm doing:
    and it is not rewritten URL.
    But. If I have rule
    And doing:
    It work.
    Any ideas?
  10. webizen

    webizen Well-Known Member

    you need to escape '+' in your matching pattern. iow, use '\+' instead of '+'.
  11. Simon

    Simon Member

    I already tried to do. The fact that the "+" should be replaced by "20%"
    To do this, have a rule, but it does not work.

    May be a bug in these rules?
  12. webizen

    webizen Well-Known Member

    pls see rewrite log below. '+' is replaced with '%20'. So rewrite works as expected.

  13. Simon

    Simon Member

    Hm, ok.
    You make it work.
    Thank so much for your time. We'll investigate further.
  14. webizen

    webizen Well-Known Member

    i did not change anything. just show you how to debug the issue using rewrite logging.
  15. Simon

    Simon Member

    Yes, I understand.
    Thank you very much for your help and your time.

Share This Page