Redirect Hosts
NginxProxyGuard's redirect host feature allows you to easily configure traffic redirection between domains.
Overview
Redirect hosts forward incoming requests to a different URL. Unlike proxy hosts, they don't forward traffic to a backend server but instead tell the client to navigate to a new URL.
Common Use Cases
1. Force HTTP → HTTPS Redirect
http://example.com → https://example.com
Convert all HTTP traffic to HTTPS for security.
2. WWW Subdomain Consolidation
http://www.example.com → https://example.com
https://www.example.com → https://example.com
Unify www/non-www for SEO and consistency.
3. Domain Migration
https://old-domain.com/* → https://new-domain.com/*
Forward traffic when moving from an old domain to a new one.
4. Path Redirect
https://example.com/old-page → https://example.com/new-page
Connect old URLs to new URLs when restructuring sites.
Supported Status Codes
| Status Code | Type | Description | Caching |
|---|---|---|---|
| 301 | Permanent | Search engines index new URL | Browser cached |
| 302 | Temporary | Search engines keep original URL | Not cached |
| 307 | Temporary Redirect | Preserves HTTP method (POST → POST) | Not cached |
| 308 | Permanent Redirect | Preserves HTTP method + permanent | Browser cached |
When to Use Which Code?
- 301: Domain changes, www consolidation, permanent changes
- 302: A/B testing, temporary maintenance pages
- 307: Temporary redirects that must preserve POST requests
- 308: Permanent redirects that must preserve POST requests
Configuration
Basic Setup
- Navigate to Redirects menu
- Click Add Redirect Host button
- Enter the following:
- Source Domain: The original domain to redirect
- Target URL: The redirect destination URL
- Status Code: Select from 301, 302, 307, 308
- Preserve Path: Whether to append original path to target URL
Preserve Path Option
With Preserve Path enabled:
https://old.com/blog/post-1 → https://new.com/blog/post-1
https://old.com/about → https://new.com/about
With Preserve Path disabled:
https://old.com/blog/post-1 → https://new.com/
https://old.com/about → https://new.com/
Wildcard Support
Redirect hosts support wildcard domains:
*.example.com → https://example.com
Redirects all subdomains (blog.example.com, api.example.com, etc.) to the main domain.
SSL Certificate Integration
Redirect hosts also need SSL certificates for HTTPS:
- Issue certificate for source domain in Certificates menu
- Select the certificate in redirect host settings
- Enable automatic HTTP → HTTPS redirect
Differences from Proxy Hosts
| Feature | Proxy Host | Redirect Host |
|---|---|---|
| Traffic Handling | Proxy to backend | Client redirect |
| Response | Backend response | 3xx status code |
| Content Modification | Possible | Not possible |
| Security Features | WAF, bot filter, etc. | Basic SSL only |
| Use Case | Serving applications | URL transitions |
Best Practices
SEO Recommendations
-
Use 301/308 for permanent changes
- Allows search engines to index new URL
-
Avoid redirect chains
- Set A → C directly instead of A → B → C
-
Utilize path preservation
- Enable preserve path when site structure is identical
Performance Optimization
-
Remove unnecessary redirects
- Redirects cause additional requests
-
Leverage caching
- 301/308 are cached by browsers, reducing repeat requests
Troubleshooting
Infinite Redirect Loop
- Check if source and target are the same domain
- Verify no conflict between proxy host and redirect host
Redirect Not Working
- Verify DNS settings are correct
- Check SSL certificate is valid
- Perform nginx config sync (Sync to Nginx)
POST Requests Converting to GET
- Use 307 or 308 status codes
- 301/302 may convert POST to GET