How to redirect a domain with html extension in Nginx

A WordPress website needs to migrate to a different domain, on a new domain site use static HTML pages. On the source site, WordPress is configured to use URL like https://domain1/page-name/, on the new server, the same page available on URL https://domain2/page-name.html

Source = https://domain1/page-name/
Destinatation = https://domain2/page-name.html

To do the redirection, edit Nginx configuration for the website, on top of it (inside server entry), add

rewrite ^/$ https://new-domain.tld permanent;
rewrite ^(.*)/$ https://new-domain.tld$1.html permanent;
rewrite ^(.*)$ https://new-domain.tld$1.html permanent;

Restart Nginx

systemctl restart nginx

See Nginx Redirect

Need help with Linux Server or WordPress? We can help!

Leave a Reply

Your email address will not be published. Required fields are marked *