How to set posts redirect to a new domain

Linux, snippet, Uncategorized, Wordpress, , , , , Leave a comment

I’m moving out a blog to a new domain, and redirect all posts specifically to a new domain.

http://olddomain.com/category/postname

should go to

http://newdomain.com/category/postname

Apache Server

On Apache that allows .htaccess, you can add this line on top of the file:

RewriteEngine on
RewriteRule ^(.*)$ http://www.newsite.COM/$1 [R=301,L]

Nginx Server

On Nginx, add this line on server block configuration file:

server {
return 301 http://newdomain.com$request_uri;
}

Reload or restart Nginx for the change to take effect.