New domain for existing website - smooth switch?
For years now, I’ve hosted a relative’s website at “domain-current.com”. They recently purchased “domain-new.com” and would prefer this new domain become their primary domain.
I’d like to do a few things, but I’m unsure how:
- Point domain-new.com to the existing
/public
directory (where domain-current.com currently points) - People who enter domain-current.com automatically go to domain-new.com (their browser’s address bar changes) via a 302 redirect
- Eventually, maybe a year from now, completely remove domain-current.com from my linode
I’ve already done the following:
- Updated domain-new.com’s name-servers to linode’s
- Added domain-new.com to the Domains area of my linode dashboard (but I’m not sure if I picked the right options / configuration)
…and this is where my mind goes blank; what else do I need to do?
I seriously appreciate any and all responses!
5 Replies
Well presumably you have a web server running on the old domain's IP address.
Either your old server or you can point the old domain to the new server.
Now this web server will be receiving http(s) requests when someone requests a page from the old domain.
And so this web server needs to respond to such page requests with an http 302 (or 301 - "permanent", maybe after you've tested everything thoroughly) that point to the new domain / web site.
For nginx, it's done by adding a server block with a server_name.
This will handle old-domain.com
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_ stuff here
server_name OLD_DOMAIN;
index index.html;
rewrite ^ $scheme://NEW_DOMAIN$uri last;
# NOTE - no content serving directives, all we're doing
# is redirecting from old domain to new domain
}
And this server block will handle the new domain:
server {
listen 443 ssl http2;
listen [::]:443 ssl http2;
ssl_ stuff here
server_name NEW_DOMAIN;
# Below: directives for serving new web site content
index index.html;
root /var/www/html;
# Root directory
location / {
try_files $uri $uri/ =404;
}
# and so on.....
}
@kmansoft Thanks for your reply! I realize now that there are details I should’ve shared initially.
The website (codebase, server, IP address) is going to remain untouched, ideally anyway. I just want the new domain to point to the current website, where it already is hosted on my linode.
Thanks, also, for the nginx code examples; any chance you know what I might do in Apache though? I remember setting up virtual host(s) ages ago, and I wonder if I need to tinker with them?
I haven't used Apache in years, but it should be same principle:
Your web server - if it's same web server for both domains - will receive requests for both domains and will need to handle them differently.
Old domain -> redirect, New domain -> serve content.
This should help:
https://httpd.apache.org/docs/2.4/rewrite/remapping.html#canonicalhost
<VirtualHost *:80>
# Match requests to old domain
ServerName OLD_DOMAIN.com
# More "old" domain names if any
ServerAlias example.com notthis.example.com www.OLD_DOMAIN.com
# Redirect (http 302 is default) to new domain
Redirect "/" "http://NEW_DOMAIN.com/"
# And this is a permanent 301 redirect when you're ready
# Redirect permanent "/" "http://NEW_DOMAIN.com/"
</VirtualHost>
<VirtualHost *:80>
# New domain, serve content
ServerName NEW_DOMAIN.com
</VirtualHost>
Port 80 is for plain http and for https it's 443. Maybe you'll need both.
If it's different servers - the old web server will need the "redirect old to new domain" block and the new web server will just serve content under new domain.