madewithlove / htaccess-cli
世界上最好的 htaccess 测试器的 CLI 接口。
Requires
- php: ^8.0
- http-interop/http-factory-guzzle: ^1.0
- madewithlove/htaccess-api-client: ^2.3
- php-http/guzzle7-adapter: ^1.0
- symfony/console: ^3.0 || ^4.0 || ^5.0 || ^6.0
- symfony/yaml: ^3.0 || ^4.0 || ^5.0 || ^6.0
Requires (Dev)
- phpstan/phpstan: ^1.0.0
- phpunit/phpunit: ^9.5
This package is auto-updated.
Last update: 2024-09-10 04:23:28 UTC
README
一个 CLI 工具,用于测试 .htaccess 文件的行为。
安装
要开始分析你的代码,请在 Composer 中引入 htaccess CLI。
composer require --dev madewithlove/htaccess-cli
Composer 将在 bin-dir 中安装 htaccess-cli 的可执行文件,默认为 vendor/bin。
全局安装
composer global require madewithlove/htaccess-cli
然后确保你在 PATH
中有全局 Composer 二进制文件目录。这个目录取决于平台,请参阅 Composer 文档 <https://getcomposer.org.cn/doc/03-cli.md#composer-home>
以获取详细信息。这允许你在系统中的任何位置使用工具作为 htaccess
。
用法
从包含 .htaccess 文件的目录中运行 .htaccess CLI 测试器。
# using global installation htaccess http://localhost/foo # using project-specific installation vendor/bin/htaccess http://localhost/foo
其中 url 是你想要测试 .htaccess 文件请求的 URL。
通过 Docker 使用
# install the container docker pull madewithlove/htaccess-cli # run the htaccess tester in the current folder docker run --rm -v $PWD:/app madewithlove/htaccess-cli [url] <options>
作为 GitHub Action 使用
如果你想验证 .htaccess 文件在 GitHub Action 中的行为,请查看 https://github.com/madewithlove/htaccess-cli-github-action。
CLI 选项
以下选项可用
-r, --referrer[=REFERRER] The referrer header, used as HTTP_REFERER in apache
--http-user-agent[=HTTP_USER_AGENT] The User Agent header, used as HTTP_USER_AGENT in apache
-s, --server-name[=SERVER-NAME] The configured server name, used as SERVER_NAME in apache
-e, --expected-url[=EXPECTED-URL] When configured, errors when the output url does not equal this url
--share When passed, you'll receive a share url for your test run
-l, --url-list[=URL-LIST] Location of the yaml file containing your url list
-p, --path[=WORKING_DIR] Path to the location of the .htaccess file you wish to test
-h, --help Display a help message
多 URL 的使用
要测试多个 URL 的一个 htaccess 文件,你可以使用包含它们的 yaml 文件。
- http://localhost/foo - http://localhost/bar
如果你想为每个测试的 URL 传递预期的 URL,你可以使用这个 yaml 结构,其中每个 URL 映射到一个预期的 URL。
http://localhost/foo: http://localhost/test http://localhost/bar: http://localhost/test
然后你可以使用以下命令运行命令
htaccess --url-list ./url-list.yaml
测试工作目录
如果你想测试当前工作目录之外的一个 .htaccess
文件,你可以在命令中使用 -p ./path_to_directory
选项。例如,
htaccess -p ./html http://localhost/
注意
此工具仅模拟服务器的一次通过,而 Apache 如果你在同一域名上返回,则会多次执行。这可能是我们未来可能会添加的功能,但现在是限制。