https://github.com/madewithlove/htaccess-api-client
API client for the best htaccess tester in the world
https://github.com/madewithlove/htaccess-api-client
hacktoberfest php
Last synced: about 1 year ago
JSON representation
API client for the best htaccess tester in the world
- Host: GitHub
- URL: https://github.com/madewithlove/htaccess-api-client
- Owner: madewithlove
- License: gpl-3.0
- Created: 2019-11-20T14:55:17.000Z (over 6 years ago)
- Default Branch: main
- Last Pushed: 2024-07-10T03:12:39.000Z (almost 2 years ago)
- Last Synced: 2025-03-24T09:21:38.606Z (over 1 year ago)
- Topics: hacktoberfest, php
- Language: PHP
- Homepage: https://htaccess.madewithlove.be/
- Size: 207 KB
- Stars: 9
- Watchers: 10
- Forks: 1
- Open Issues: 2
-
Metadata Files:
- Readme: README.md
- Funding: .github/FUNDING.yml
- License: LICENSE
Awesome Lists containing this project
README
# htaccess-api-client
[](https://github.com/madewithlove/htaccess-api-client/actions?query=branch%3Amain)
[](https://packagist.org/packages/madewithlove/htaccess-api-client)
[](https://packagist.org/packages/madewithlove/htaccess-api-client)
[](https://codecov.io/gh/madewithlove/htaccess-api-client)
This is an API client to interact with the [Htaccess tester](https://htaccess.madewithlove.com/).
### Installation
```bash
composer require madewithlove/htaccess-api-client
```
### Usage
The package can be used with every PSR-compatible http client. In this example, we're going to be using
guzzle's PSR adapter.
```php
use Http\Factory\Guzzle\ServerRequestFactory;
use Http\Adapter\Guzzle6\Client;
use Madewithlove\HtaccessClient
$client = new HtaccessClient(
new Client(),
new ServerRequestFactory()
);
$response = $client->test(
'http://localhost',
'RewriteRule .* /foo [R]'
);
$response->getOutputUrl(); // "http://localhost/foo"
$response->getLines();
/*
array(1) {
[0]=>
object(Madewithlove\ResultLine)#30 (5) {
["line":"Madewithlove\ResultLine":private]=> string(23) "RewriteRule .* /foo [R]"
["message":"Madewithlove\ResultLine":private]=> string(98) "The new url is http://localhost/foo
Test are stopped, a redirect will be made with status code 302"
["isMet":"Madewithlove\ResultLine":private]=> bool(true)
["isValid":"Madewithlove\ResultLine":private]=> bool(true)
["wasReached":"Madewithlove\ResultLine":private]=> bool(true)
}
}
*/
```
### Server variables
Htaccess Tester supports passing server variables to be evaluated by the rewrite rules.
We currently support the following variables.
Server variables can be passed to the `test()` and `share()` methods.
```php
$serverVariables = ServerVariables::default()->with(
'SERVER_NAME',
'example.com'
);
$response = $client->test(
'http://localhost',
'RewriteCond %{SERVER_NAME} example.com
RewriteRule .* /foo [R]',
$serverVariables
);
$response = $client->share(
'http://localhost',
'RewriteCond %{SERVER_NAME} example.com
RewriteRule .* /foo [R]',
$serverVariables
);
```