DNS Redirects and URL Forwarding
Learn how DNS redirects work, the difference between 301 and 302 redirects, and how to use CNAME records, HTTP redirects, and URL forwarding for your domain.
DNS redirects and URL forwarding are techniques to send visitors from one domain or URL to another. While DNS itself doesn't perform HTTP redirects, several DNS-related methods can achieve the same result. Understanding the options helps you choose the right approach.
DNS Redirect vs. HTTP Redirect
It's important to understand that DNS and HTTP redirects work at different layers:
| Layer | Mechanism | What Happens |
|---|---|---|
| DNS | CNAME, A record | Resolves a domain to a different name or IP β the browser doesn't know it was redirected |
| HTTP | 301, 302 redirect | The server responds with a redirect status code β the browser's URL bar changes |
DNS alone cannot change the URL in a browser's address bar. For that, you need an HTTP redirect served by a web server.
Method 1: CNAME Records (DNS-Level Alias)
A CNAME record points one domain to another at the DNS level:
blog.example.com. 3600 CNAME example.com.When someone visits blog.example.com, DNS resolves it to example.com's IP address. The browser connects to that IP, but the URL bar still shows blog.example.com.
When to Use CNAME
- Pointing subdomains to cloud services (
app.example.comβmyapp.herokuapp.com) - Pointing
wwwto the apex domain - When you don't need the URL to change in the browser
Limitations
- Doesn't work at the apex domain (use ALIAS instead)
- The URL in the browser doesn't change
- Cannot redirect to a specific path (e.g., can't redirect to
example.com/blog)
Method 2: HTTP 301 Redirect (Permanent)
A 301 redirect tells browsers and search engines that a page has permanently moved to a new URL:
HTTP/1.1 301 Moved Permanently
Location: https://www.example.com/Example: Redirect Non-WWW to WWW
Nginx:
server {
listen 80;
server_name example.com;
return 301 https://www.example.com$request_uri;
}Apache (.htaccess):
RewriteEngine On
RewriteCond %{HTTP_HOST} ^example\.com [NC]
RewriteRule ^(.*)$ https://www.example.com/$1 [L,R=301]When to Use 301
- Permanently moving a site to a new domain
- Consolidating
http://tohttps:// - Redirecting
example.comtowww.example.com(or vice versa) - Migrating from an old URL structure to a new one
SEO Impact
301 redirects pass most link equity (SEO value) to the new URL. Search engines will eventually update their index to show the new URL.
Method 3: HTTP 302 Redirect (Temporary)
A 302 redirect indicates a temporary move:
HTTP/1.1 302 Found
Location: https://maintenance.example.com/When to Use 302
- Temporary maintenance pages
- A/B testing different URLs
- Geolocation-based routing to different content
- Any redirect that might be reversed in the future
SEO Impact
302 redirects tell search engines to keep the original URL in their index, since the redirect is temporary.
Method 4: HTTPS Record (DNS-Level)
The newer HTTPS record type can signal to browsers that a domain supports HTTPS, eliminating the need for an HTTP-to-HTTPS redirect:
example.com. 3600 IN HTTPS 1 . alpn="h2,h3"This doesn't replace HTTP redirects but reduces the latency of the initial HTTP β HTTPS upgrade for supporting browsers.
Common Redirect Scenarios
Redirect HTTP to HTTPS
DNS setup (point both to the same server):
example.com. 3600 A 192.0.2.1
www.example.com. 3600 A 192.0.2.1Web server handles the redirect:
server {
listen 80;
server_name example.com www.example.com;
return 301 https://$host$request_uri;
}Redirect Apex to WWW
DNS setup:
example.com. 3600 A 192.0.2.1
www.example.com. 3600 CNAME myapp.example.com.Web server on 192.0.2.1:
server {
listen 443 ssl;
server_name example.com;
return 301 https://www.example.com$request_uri;
}Redirect Old Domain to New Domain
DNS setup (old domain points to a redirect server):
olddomain.com. 3600 A 192.0.2.99
www.olddomain.com. 3600 A 192.0.2.99Redirect server:
server {
listen 443 ssl;
server_name olddomain.com www.olddomain.com;
return 301 https://newdomain.com$request_uri;
}Redirect Subdomain to External Service
DNS setup:
docs.example.com. 3600 CNAME example.gitbook.io.No redirect needed β the CNAME handles it at the DNS level. The content is served from GitBook but accessed via your subdomain.
301 vs. 302 vs. CNAME: Decision Guide
| Scenario | Recommended Method |
|---|---|
| Point subdomain to cloud service | CNAME |
| Move to a new domain permanently | 301 redirect |
| Redirect HTTP to HTTPS | 301 redirect |
| Redirect non-www to www | 301 redirect |
| Temporary maintenance page | 302 redirect |
| Redirect to a specific URL path | 301/302 redirect (DNS can't do paths) |
| Apex domain to cloud service | ALIAS record + web server redirect if needed |
Setting Up DNS for Redirects in DNScale
For most redirect scenarios, you need DNS records pointing to the server that will issue the HTTP redirect.
Using the Dashboard
- Navigate to your zone in DNScale
- Add an A record pointing to your redirect server's IP
- Or add a CNAME record pointing to the destination domain (for subdomain aliases)
Using the API
# Point the domain to your redirect server
curl -X POST "https://api.dnscale.eu/v1/zones/{zone_id}/records" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "@",
"type": "A",
"content": "192.0.2.99",
"ttl": 3600
}'Related Topics
- CNAME Records Explained β how CNAME aliases work
- CNAME vs A Record β choosing the right record type
- What Is an ALIAS Record β CNAME-like behavior at the apex
- What Is an HTTPS Record β signal HTTPS support via DNS
Conclusion
DNS records and HTTP redirects work together to route users to the right destination. Use CNAME for subdomain aliases where the URL doesn't need to change, and HTTP 301/302 redirects for permanent or temporary URL changes. DNScale makes it easy to configure the DNS side β just point your records to the right servers and let your web server handle the redirect logic.