facebook / hhvm

A virtual machine for executing programs written in Hack.
https://hhvm.com
Other
18.21k stars 3k forks source link

How use [rewrite_rules][conditions] with REQUEST_FILENAME in .ini? #7816

Open brcontainer opened 7 years ago

brcontainer commented 7 years ago

HHVM Version

3.18.1

Standalone code, or other way to reproduce the problem

I expected to ignore only files, the folders would still go through rewrite (note that the ini is "commented"):

hhvm.virtual_host[default][check_existence_before_rewrite] = false

;hhvm.virtual_host[default][rewrite_rules][common][conditions][-d][pattern] = "%{REQUEST_FILENAME}"
;hhvm.virtual_host[default][rewrite_rules][common][conditions][-d][type] = request
;hhvm.virtual_host[default][rewrite_rules][common][conditions][-d][negate] = true

hhvm.virtual_host[default][rewrite_rules][common][conditions][-f][pattern] = "%{REQUEST_FILENAME}"
hhvm.virtual_host[default][rewrite_rules][common][conditions][-f][type] = request
hhvm.virtual_host[default][rewrite_rules][common][conditions][-f][negate] = true

hhvm.virtual_host[default][rewrite_rules][common][pattern] = "(.*)"
hhvm.virtual_host[default][rewrite_rules][common][to] = "index.php"
hhvm.virtual_host[default][rewrite_rules][common][qsa] = true

This is an "illustrative" code, I believe that -d and -f flags aren't supported.

Expected result

Ignore rewrite_rules from form pattern


I reviewed the documentation, but only found the "check_existence_before_rewrite", Is there any way to check for the existence of specific files using proxygen before applying rewrite?

mofarrell commented 7 years ago

According to the docs site:

    RewriteRules {
      * {
        pattern = regex pattern same as Apache's
        to = target format same as Apache's
        qsa = false
        redirect = 0 (default: off) | 302 | 301 | other status code

        conditions {
          * {
            pattern = regex pattern to match
            type = host | request
            negate = false
          }
        }
      }
    }

The position you are putting the flag in is a glob. The name you assign does not get used. The whole point is to allow for a vector of conditions. In this case you are just labeling the entries in the vector as -d, and -f.

There is not support for those flags.

brcontainer commented 7 years ago

@mofarrell it's pseudo-code, is only a example :)

I would just like to know if there is any way to check the file exists within [conditions].

mofarrell commented 7 years ago

Not currently. The only option available for related to that is the global one. Adding logic to support that shouldn't be too hard. The rewrite system is pretty self contained. https://github.com/facebook/hhvm/blob/master/hphp/runtime/server/virtual-host.cpp