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

Advertisement

systemctl restart nginx
Add a comment

Leave a Reply

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

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Advertisement