# 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
```bash
cargo install http-to-https-redirect
```
## Usage
Simply run the binary with appropriate permissions:
```bash
sudo http-to-https-redirect
```
**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:
```bash
sudo setcap 'cap_net_bind_service=+ep' $(which http-to-https-redirect)
http-to-https-redirect
```
### 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
```bash
git clone https://github.com/jvtubergen/http-to-https-redirect
cd http-to-https-redirect
cargo build --release
```
The binary will be available at `target/release/http-to-https-redirect`.
## License
Licensed under the MIT License. See [LICENSE.md](LICENSE.md) or http://opensource.org/licenses/MIT for details.
## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.