Description:- When someone visits your site using an old link to a page that has moved, a 301 redirect will automatically take them to the new page so they do not see a 404 ‘page not found’ error.
Redirection in WordPress: A redirect is a way for your WordPress website to automatically send users to a new address when the page they wish to visit has been moved or replaced.
The primary reason to use a 301 redirect is when your site or a page on your site has been moved, and you want to point the user to a new page instead.
It is also needed when you plan on changing the permalink of a post or page.
They allow you to tell search engines and your users that the page they are trying to reach has been permanently moved to a new location.
Redirecting your one domain to another domain in WordPress using .htaccess file
WordPress users can also set up 301 redirects by editing the .htaccess web server configuration file.
Please keep in mind that a small mistake in your .htaccess code can make your WordPress site inaccessible, and it may start showing the Internal Server Error.
That’s why it is important that you back up your .htaccess file before making any changes.
Directly Edit Your WordPress .htaccess file
You can also edit your WordPress .htaccess file directly to set up any redirects.
To edit your .htaccess file, you’ll need to connect to your website using an FTP client. The .htaccess file resides in your WordPress site’s root directory.
RewriteEngine on
RewriteCond %{HTTP_HOST} ^domain.com$ [OR]
RewriteCond %{HTTP_HOST} ^www.domain.com$
RewriteRule ^(.*)$ “https://newdomain.com/$1” [R=301,L]
