301 redirect entire domains with easy engine

Hey Hi,
I have a html based site built on easy engine stack.

I wanted to redirect every version of doanteers.com Url to https://donateers.org

Example: https://donateers.com/il/ -> 301 redirect -> https://donateers.org/il/

Can you please help me with the code? I did used the following code… but site got broken

server {
. . .
server_name donateers.com;
rewrite ^/(.*)$ https://donateers.org/$1 permanent;
. . .
}

Thanks
Suresh

Any help guys?

You have to list both the old and the new domains under server_name so it knows to listen to both. Then instead of a rewrite, use return like this

return 301 $scheme://newdomain.com$request_uri;

replacing $scheme:// will remove any issues with http vs https and will return whatever was used. If you also want to force the use of https, us that instead. And request_uri will take whatever comes after the old domain name and append it to the returned address.

And with EE4 you need to make sure that your changes persist across updates or keep a file with your changes handy so you can quickly add them back to any updated site. See if your changes will work in the persistent file in the sites/yourdomain.com/config/nginx/custom/user.conf file.

EDIT: Remember to restart or reload your sites after making changes. In EE4 use sudo ee site restart yoursitename.com

Right now, added the above code I mentioned in the main.conf file.

I guess that will overwrite when I update the EE.

Thanks @freedog96150 I ll test it out the code again now.

Please respond back on whether this hack works or not so that future people that find this post know as well. It will also allow me to put some more thought behind this from the configuration perspective.

For the record, I have WP migrations down to a 10 min task so if I ever have to change domain names I just create the new domain with EE4, copy over the wp-content/ folder contents, do a quick db export on old and import on new and a final wp search-replace on the URL and BAM! done!

1 Like

@freedomfighter2127 Sure, I ll reply back after trying this…

Very cool SOP on the WP domain migration.

Mine is just a static site and not to worry on the DB too.

I did wrote the self-answer how it solved me as of now over here.

I ll update you soon with your code too.