http-to-https-redirect
A lightweight Rust server that listens on port 80 and automatically redirects all HTTP requests to HTTPS using 301 (Moved Permanently) status codes, preserving the hostname, path, and query parameters.
Features
- Automatic HTTP to HTTPS redirection with 301 status code
- Preserves full request URI (path and query parameters)
- Respects the Host header for proper domain redirection
- Lightweight and fast, built with Hyper and Tokio
- Zero configuration needed
Installation
Usage
Simply run the binary with appropriate permissions:
Note: Running on port 80 requires root privileges or CAP_NET_BIND_SERVICE capability.
Running without sudo (Linux)
Grant the binary permission to bind to privileged ports:
Example
When a client requests:
http://example.com/path?query=value
They will be redirected to:
https://example.com/path?query=value
Use Case
Run this alongside your HTTPS server to ensure all traffic uses secure connections. This is particularly useful for:
- Enforcing HTTPS across your entire site
- Meeting security requirements that mandate encrypted connections
- Improving SEO (search engines prefer HTTPS)
- Providing a seamless redirect experience for users
Building from Source
The binary will be available at target/release/http-to-https-redirect.
License
Licensed under the MIT License. See LICENSE.md or http://opensource.org/licenses/MIT for details.
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.