Express js ip canonicalization

Im using MERN stack to build a web app. and its being hosted on a vps, and connected to a domain name. the problem is that there is two versions of the app. one on the ip adress of the vps and the other on the domain name. and this is not good for SEO. and i cant seem to find good resources on ip canonicalization or rediercting to domain name.

normally on an apache server i would use .htaccess but thats for apache. is there an equvialnt to .htaccess for expressjs. ? or any other way i can achive that.

thank you.


Submit an answer

This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

Sign In or Sign Up to Answer

These answers are provided by our Community. If you find them useful, show some love by clicking the heart. If you run into issues leave a comment, or add your own answer to help others.

Want to learn more? Join the DigitalOcean Community!

Join our DigitalOcean community of over a million developers for free! Get help and share knowledge in Q&A, subscribe to topics of interest, and get courses and tools that will help you grow as a developer and scale your project or business.


What I would usually do is to use Nginx as a reverse proxy. This will also allow you to install an SSL certificate for your website using Let’s Encrypt and certbot.

You can follow the steps on how to do that here:

Once Nginx is in place, you could use the following server block to do the IP to domain redirection:

server {
    listen 80;
    server_name your_ip;

    return 302 $scheme://$request_uri;

Regards, Bobby