如何使用 HHVM proxygen 重写规则忽略任何文件?
How ignore any files using HHVM proxygen rewrite rules?
我创建了一个这样的文件example.ini
:
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
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
并在终端中调用:
$ hhvm -m server -p 9000 -d hhvm.server.source_root=/home/user/project -c example.ini
工作正常,但是我仍然可以浏览与项目位于同一文件夹中的现有文件,但我想要的是所有请求都应发送到 "index.php",我该怎么做?
如果您希望所有请求的 100% 通过重写规则,请添加:
hhvm.virtual_host[default][check_existence_before_rewrite]= false
但是,除非您要构建 API 或具有 100% 动态内容的内容,否则请避免这种情况。静态内容,如文本、html 文件、图像等...应该允许提供,而无需在您的 PHP 代码中进行评估。
我建议将所有敏感文件和代码(您的 index.php 除外)保存在您的网络根目录之外。只将静态文件放在此文件夹中,当然还有您的 index.php,不要将其他代码放在此处。
我创建了一个这样的文件example.ini
:
hhvm.server.type = proxygen
hhvm.server.default_document = index.php
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
并在终端中调用:
$ hhvm -m server -p 9000 -d hhvm.server.source_root=/home/user/project -c example.ini
工作正常,但是我仍然可以浏览与项目位于同一文件夹中的现有文件,但我想要的是所有请求都应发送到 "index.php",我该怎么做?
如果您希望所有请求的 100% 通过重写规则,请添加:
hhvm.virtual_host[default][check_existence_before_rewrite]= false
但是,除非您要构建 API 或具有 100% 动态内容的内容,否则请避免这种情况。静态内容,如文本、html 文件、图像等...应该允许提供,而无需在您的 PHP 代码中进行评估。
我建议将所有敏感文件和代码(您的 index.php 除外)保存在您的网络根目录之外。只将静态文件放在此文件夹中,当然还有您的 index.php,不要将其他代码放在此处。