Tirehtööri is a Django service that provides URL redirection functionality.
- URL redirection with Django
- Customizable redirection rules
- Support for 301/302 status codes
- Simple wildcard matching
- Append matched path and query parameters to the target URL
- Support both case-insensitive and case-sensitive matching
- Support for multiple domains
- Import redirection rules from a JSON file
-
Make a copy of the example environment file:
cp .env.example .env
-
Start the Docker containers:
docker compose up
-
Access the application at
http://localhost:8000.
You can add redirection rules using the Django admin interface.
Each redirection rule belongs to a domain, so you need to create a domain first.
Note that when using localhost as a domain, you need to include the port number
in the domain name (e.g., localhost:8000).
The redirection rules do not support regular expressions.
The match_subpaths option matches any path starting with the specified path, like
a wildcard. The append_subpath option appends the matched subpath to the target URL.
For example, with the path /foo and match_subpaths enabled, the rule matches
/foo, /foo/bar, /foo/bar/baz, etc. With the path /foo, destination
acme.test, and both options enabled, the rule matches /foo/bar and redirects
to acme.test/bar.
You can import redirection rules from a JSON file using the Django management command
import_redirection_rules.
docker compose exec django python manage.py import_redirection_rules path/to/rules.jsonSee --help for more information on the command:
docker compose exec django python manage.py import_redirection_rules --helpThe JSON file should have the following structure:
[
{
"domain_names": ["acme.test", "www.acme.test"],
"rules": [
{
// Required fields
"path": "/foo",
"destination": "https://foo.test/bar",
// Optional fields
"permanent": true,
"case_sensitive": false,
"match_subpaths": false,
"append_subpath": false,
"pass_query_string": false,
"notes": "An optional note"
},
// ...more rules...
]
}
]Run the tests using pytest:
pytestThis project is licensed under the MIT License - see the LICENSE file for details.