https://github.com/settermjd/url-redirector
This is a simple package that simplifies the process of performing redirects from one absolute URL to another. It's not meant to be, in any way, sophisticated.
https://github.com/settermjd/url-redirector
Last synced: 8 months ago
JSON representation
This is a simple package that simplifies the process of performing redirects from one absolute URL to another. It's not meant to be, in any way, sophisticated.
- Host: GitHub
- URL: https://github.com/settermjd/url-redirector
- Owner: settermjd
- Created: 2017-07-27T10:21:31.000Z (almost 9 years ago)
- Default Branch: master
- Last Pushed: 2018-02-06T02:56:32.000Z (over 8 years ago)
- Last Synced: 2025-07-20T11:48:02.993Z (11 months ago)
- Language: PHP
- Size: 8.79 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Absolute URL Redirector
This is a simple package that simplifies the process of performing redirects from one absolute URL to another.
It's not meant to be, in any way, sophisticated.
## Installing
To install the module, use Composer by running `composer require settermjd/url-redirector`.
## Getting Started
The constructor takes two arguments:
1. An array. This is a simple key/value list of URLs that require redirecting, and where they should be redirected to
2. The currently requested URL.
The package provides two functions:
- `requiresRedirect()`: This tests if the requested URL requires a redirect
- `getRedirectUrl()`: This retrieves the URL that the current request should be redirected to
If you just want to test, use the first, if you want to redirect, use the second, which uses the first internally.
After initializing the object, pass the return value from `getRedirectUrl()` to PHP's [header](http://php.net/manual/de/function.header.php) function, as in the example below, and the request will be redirected.
```php
requiresRedirect()) {
header(sprintf('Location: %s', $redirector->getRedirectUrl()));
exit;
}
```
## Running the Tests
To run the unit tests, run `composer test`.