Setting up a permanent (301) redirection from your old URL to a new URL in WordPress with .htaccess is the most efficient and search engine-friendly method. Here I share how I properly redirected some of my old pages from the old blog to Barzrul.com.
If you have not noticed yet, I am moving some of the pages from my old blog and redirecting them to this blog. This is because I want to give you fresh content and up-to-date article since I will no longer update the old blog.
In order to not lose the juicy link and the page rank, I use a permanent 301 redirect method. This method actually tells the search engine that the pages have moved and any update will be available on the new pages. So, the search engine will crawl the new pages and any incoming link will redirect to the new pages.
See also how to change WordPress domain address.
How to set up a permanent 301 redirect in WordPress .htaccess file
Find and open your .htaccess file. You should be able to find it in the root folder of your WordPress installation file.
Important! This should be done on your old domain.
Redirect all
- If you want to redirect everything to a new URL. Your 301 redirect command will look like this:
RewriteEngine on RewriteCond %{HTTP_HOST} ^old-domain.com [NC,OR] RewriteCond %{HTTP_HOST} ^www.old-domain.com [NC] RewriteRule ^(.*)$ http://new-domain.com/$1 [L,R=301,NC]
Please change the old-domain
to your old URL and new-domain
to your new URL.
Redirect specific page
- If you want to redirect only one page to a new URL. Your 301 redirect command will look similar like this:
RewriteEngine on RewriteCond %{HTTP_HOST} ^old-domain\.com$ [OR] RewriteCond %{HTTP_HOST} ^www\.old-domain\.com$ RewriteRule ^how\-to\-set\-up\-301\-redirect\-in\-wordpress\-htaccess\/?(.*)$ "http\:\/\/new-domain\.com\/how\-to\-set\-up\-301\-redirect\-in\wordpress\-htaccess$1" [R=301,L]
Please change the old-domain
to your old URL and new-domain
to your new URL.
Note: If you are using W3TC plugin in your WordPress blog or site, find the following line and insert the 301 redirect command right above it. Or your redirect command will have conflict.
# BEGIN W3TC Page Cache core
Thank you to the ServerFreak technical support team’s help, I was able to properly implement a permanent 301 redirect from my old blog to this new page.