Custom Domain Redirects
Custom domain redirects enable automatic visitor redirection from one URL to another. This feature is useful for page renaming, creating short URLs, site reorganization, and maintaining SEO rankings.
Redirects only work on custom domains, not standard pages domain URLs.
Prerequisites
- Repository with a
.pagesfile - Custom domain configured in
.pagesfile - DNS configured and pointing to Bovine Pages Server
- Custom domain registered by visiting your pages URL
How It Works
- Create a
.redirectsfile in your repository root - Visit
https://your-custom-domain.com/LOAD_REDIRECTSto activate - Server reads redirects and configures Traefik to handle them
- Traefik automatically redirects visitors using 301 permanent redirects
- Redirects are stored persistently in Redis cache
Setup Steps
Step 1: Create .redirects File
Create a .redirects file in your repository root with the format FROM:TO (one redirect per line):
FROM= URL path to redirect fromTO= URL path or absolute URL to redirect to- Lines starting with
#are treated as comments - Empty lines are allowed
Example .redirects file:
# Simple page rename
about.html:about-us.html
# Directory reorganization
posts/first-post:blog/first-post
posts/second-post:blog/second-post
# Short URLs
docs:documentation/getting-started/index.html
# External redirect
github:https://github.com/yourusername
Step 2: Verify .pages File
Ensure your .pages file has a custom domain configured:
enabled: true
custom_domain: www.example.com
Step 3: Commit and Push
Commit your .redirects file and push to your repository:
git add .redirects
git commit -m "Add URL redirects"
git push
Step 4: Activate Redirects
Visit the special endpoint to load your redirects:
https://www.example.com/LOAD_REDIRECTS
You’ll see a success page displaying all your active redirects.
Step 5: Test Redirects
Test your redirects by visiting the original URLs to verify they redirect correctly.
Redirect Examples
Simple Page Rename
about.html:about-us.html
Directory Reorganization
posts/first-post:blog/first-post
posts/second-post:blog/second-post
Short URLs
docs:documentation/getting-started/index.html
External Redirects
github:https://github.com/yourusername
linkedin:https://linkedin.com/in/yourprofile
Trailing Slashes
about:about/
blog/:blog
Root to Subdirectory
/:app/
Updating Redirects
To update your redirects:
- Edit the
.redirectsfile in your repository - Commit and push the changes
- Reload via
https://your-custom-domain.com/LOAD_REDIRECTS
Manual reload is required after every change to the .redirects file.
Resource Limits
The default maximum is 25 redirects per domain. The server reads only the first 25 lines of your .redirects file.
Troubleshooting
| Issue | Solution |
|---|---|
| “Custom domain not configured” | Add custom_domain field to your .pages file |
| “No .redirects file found” | Create .redirects file in repository root |
| “Redis cache required” | Contact your administrator to enable Redis |
| Redirects not working | Verify domain registration, DNS configuration, and redirect format |
| File content shows instead of loading | Use custom domain URL, not pages domain URL |
| Changes not appearing | Reload via /LOAD_REDIRECTS endpoint |
Security Considerations
Allowed Use Cases
- Redirecting between pages on your site
- Redirecting to external websites
- Creating short URLs
- Site reorganization
Not Allowed
- JavaScript injection attempts
- HTML injection attempts
- Code execution attempts
- Accessing other users’ repositories
Best Practices
- Use 301 redirects (automatic)
- Avoid redirect chains (A→B→C)
- Test thoroughly before relying on redirects
- Document redirect purposes with comments
- Clean up old redirects after sufficient time
Limitations
- Custom domains only - Redirects do not work on standard pages domain URLs
- Redis required - Redis cache must be enabled on the server
- Manual activation - Must visit
/LOAD_REDIRECTSendpoint after changes - Maximum redirects - Default limit of 25 redirects per domain
- 301 redirects only - All redirects are permanent (301)
- No wildcard support - Each redirect must be explicitly defined
Advanced Topics
Multiple Domains
Each repository can have independent redirects. If you use multiple custom domains pointing to the same repository, each domain can have its own redirect configuration.
Redirect Priority
When multiple redirects could match, the first matching redirect wins. Order your redirects carefully in the .redirects file.
Performance
Redirects have zero performance impact on your site. Traefik handles redirects at the network level with sub-millisecond overhead (<1ms).
Complete Example
Here’s a complete example showing blog reorganization:
Repository structure:
.
├── .pages
├── .redirects
└── public/
├── index.html
├── blog/
│ ├── 2024-01-post.html
│ └── 2024-02-post.html
└── old-posts/
├── first.html
└── second.html
.pages file:
enabled: true
custom_domain: blog.example.com
.redirects file:
# Reorganize old posts
old-posts/first.html:blog/2024-01-post.html
old-posts/second.html:blog/2024-02-post.html
# Short URLs
latest:blog/2024-02-post.html
Activation:
- Push the repository
- Visit
https://blog.example.com/LOAD_REDIRECTS - Test:
https://blog.example.com/old-posts/first.html→ redirects tohttps://blog.example.com/blog/2024-01-post.html
Technical Details
The redirect feature uses Traefik’s redirectregex middleware with the following characteristics:
- Configuration stored in Redis with persistent TTL
- Middleware dynamically generated from
.redirectsfile - All redirects use HTTP 301 (Permanent Redirect)
- Special characters automatically escaped for regex safety
- Implementation in
redirects.go
Requires Bovine Pages Server v0.1.1 or later.