When you need to redirect a subdomain (subdomain.example.org) to another domain (somethingelse.com) while keeping the original URL visible in the browser's address bar, you're essentially looking to implement one of these solutions:
- DNS-level proxying (CNAME flattening)
- Reverse proxy configuration
- URL masking through server-side redirects
For a true redirect without changing the visible URL, you'll need either:
; Option 1: CNAME record (if your DNS provider supports flattening)
subdomain.example.org. IN CNAME somethingelse.com.
; Option 2: A record pointing to your server's IP
subdomain.example.org. IN A 192.0.2.1
For Apache servers, create a .htaccess file in the subdomain's root:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %{HTTP_HOST} ^subdomain\.example\.org$ [NC]
RewriteRule ^(.*)$ http://somethingelse.com/$1 [P]
</IfModule>
For Nginx, add this to your server block:
server {
server_name subdomain.example.org;
location / {
proxy_pass http://somethingelse.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
}
If using Cloudflare:
- Create a CNAME record pointing subdomain.example.org to somethingelse.com
- Enable "Proxy" (orange cloud icon)
- Set SSL to "Full" or "Full (strict)"
Watch for these pitfalls:
- Mixed content warnings (HTTP/HTTPS mismatch)
- DNS propagation delays (up to 48 hours)
- SSL certificate needs to cover both domains
For Node.js applications using Express:
const express = require('express');
const { createProxyMiddleware } = require('http-proxy-middleware');
const app = express();
app.use('/', createProxyMiddleware({
target: 'http://somethingelse.com',
changeOrigin: true,
xfwd: true
}));
app.listen(3000);
When you need to redirect subdomain.example.org
to somethingelse.com
while keeping the original URL visible in the browser's address bar, you're dealing with URL masking. This requires more than simple HTTP redirects (301/302) or frame-based solutions.
Many beginners try to solve this purely through DNS records:
; THIS WON'T WORK FOR MASKING
subdomain.example.org. IN CNAME somethingelse.com.
DNS records alone cannot achieve URL masking. CNAMEs just alias one name to another, while A records point to IP addresses - neither handles the content serving logic.
Option 1: Reverse Proxy (Recommended)
Configure your web server to proxy requests:
For Apache (.htaccess)
RewriteEngine On
RewriteRule ^(.*)$ http://somethingelse.com/$1 [P]
For Nginx
location / {
proxy_pass http://somethingelse.com;
proxy_set_header Host $host;
proxy_set_header X-Real-IP $remote_addr;
}
Option 2: Virtual Host Configuration
If both domains are on the same server:
<VirtualHost *:80>
ServerName subdomain.example.org
DocumentRoot /var/www/somethingelse.com/public_html
</VirtualHost>
If you're on shared hosting without server config access:
- Check if your host offers "domain parking" or "URL masking" features
- Use PHP as last resort (not ideal for performance):
<?php
// subdomain/index.php
include('http://somethingelse.com');
?>
When implementing this:
- SSL certificates must cover both domains
- Search engines may treat this as duplicate content
- Session/cookie handling needs special attention