Redirect apache2 with custom header

Discussion in 'Apache' started by kory01, Mar 1, 2023.

  1. #1
    Hi, I'm trying to redirect requests from a domain according to the value of a custom HEADER, but i can't

    This is what i did

    Header set testing "Test"
    RewriteCond %{testing} !^$
    RewriteRule ^ - [F]
    Code (markup):
    With CURL I get the header, but not the 403
    curl --head http://domainHTTP/1.1 200 OK
    Server: Apache/2.4.54 (Debian)
    Vary: Accept-Encoding
    testing: Test
    Content-Type: text/html
    Code (markup):
    This same with existing HEADERS works correctly
    RewriteCond %{REMOTE_ADDR} !^$
    RewriteRule ^ -[F]
    Code (markup):
    Response
    curl --head http://domain
    HTTP/1.1 403 Forbidden
    Server: Apache/2.4.54 (Debian)
    Code (markup):
    Hope you can help, warm regards
     
    kory01, Mar 1, 2023 IP
  2. dascos

    dascos Member

    Messages:
    11
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    33
    #2
    RewiteCond has, usually, 2 params.
    A "test" and a "condition".
    If I'm right with your question, you have to do something like this
    
    RewriteCond "%{REQUEST_METHOD}" "HEAD"
    RewriteCond "%{HTTP:header}" "(match1|match2|match3)"
    RewriteRule "-" [F]
    
    Code (markup):
     
    dascos, Mar 28, 2023 IP