301 Redirects from old WordPress domain

You didn’t mention what http server you are using so I’ll assume it is either Apache or Nginx.

Apache

The most efficient method would be to include a “redirect” statement within the block;

<VirtualHost your_ip_address:80>

ServerName example.com
ServerAlias www.example.com

Redirect 301 / https://example.ro/

</VirtualHost>

By doing it within your httpd.conf the work is done prior to any site resources being served. It will effectively take all traffic for example.com to example.ro as soon as it is requested.

Another method, again for Apache, is via the .htaccess file. This method requires you place a .htaccess file into each sub-directory because URLs like example.com/wp-admin would still succeed without redirection.

Your .htaccess in the root folder for your domain needs the following added.

Redirect 301 / https://example.ro/

After modifying Apache’s config restart it and the changes will be effective immediately.

Nginx

Nginx is just as simple although it does not support .htaccess files. The redirection is performed within the Server block.

For example;

server {
listen your_ip_address:80;
server_name example.com www.example.com;

return 301 https://example.ro$request_uri;

}

Reload Nginx and the redirection will become active.

Browser Cache

Clear your browser cache otherwise you might have issues. Google Chrome drives me mental when I make a change and it doesn’t care until I clean the cache, curse & swear at it and try again.

I hope this helps someone.