Google recommends using 301 redirects to promote SEO when changing the URL of a web page. To ensure users and search engines are redirected to the correct page, it’s advised a server-side 301 redirect is in place to show search engines that a page has been moved to a new location. A 301 redirect is part of facilitating a transition when moving a website to a new domain {a very small part!}, it is the go to when you need to change a URL and basically it is a staple point in the SEO field.
In order to create a successful redirect to meet Google’s standards, your server’s .htaccess file will need to be accessed when using Apache. However, should your site be hosted on a server using software, your hoster will have additional details on how to implement the redirect. We talk a little more about 301 redirects with plugins later, in most cases with modern day CMS systems this is the best option.
301 Redirects for SEO
Matt Cutts addresses the 301 in video, stating that you can lose a little link juice in the transfer. I have done thousands of 301 redirects in hundreds of situations. It usually takes 1 to 4 weeks for Google to pick up the redirect. Following this, the rankings usually transfer in about a week. Generally, the URL you are redirecting to ends up ranking in about the same position as the old URL. In some cases a little higher, in others a little lower, in some cases something goofy happens and Google doesn’t pass the ranking or the ranking ends up much lower. There are many factors to consider here such as:
- Is the new URL SEO friendly?
- What is the content on the new URL?
- Are the links and rankings applicable for the new URL?
- Does the new URL have a penalty?
- Does the new URL have any links of its own?
- Etc
In this post we talk mostly about redirects through Apache, but keep in mind that if you are using a CMS and are not a developer there are more user-friendly ways to do it. For example, in WordPress if you change a post URL it automatically adds a redirect for you if this post already went live, this is of course in the latest version. Also, again in WordPress you can use an easy plugin like Simple 301 Redirect that allows you to just copy past what you want done. In the case of a CMS like Drupal, Magento, etc, there are also easy plugins you can use. This post looks more at the technical side and explores certain situations.
Basic 301 Redirects in Apache
To perform a redirect in Apache, you’ll need to look in the root directory for .htaccess. Using the 2 lines of code below in a plain-text editor, you’ll enable the Apache mod_rewrite module and enable the ReWriteEngine in the mod_rewrite module:
Options +FollowSymLinks
RewriteEngine on
Depending on the number of URLs, content, and domains you’d like to redirect, you’ll need to add in additional lines to the .htaccess file, which are as follows:
Single Page URL
To permanently redirect a single page from one website to another use the basic code:
Redirect 301 /redirect page.html https://www.yourwebsite.com/newpage.html
Directory URL and All Content
To redirect an entire directory, all URLs, and all content, use:
RedirectMatch 301 ^/olddirectoryname/ https://www.yourwebsite/newname
Redirect New URL to Current Website
If you’ve recently purchased a new URL or have a new site that you’d like to redirect to your current website, you’re able to accomplish this using:
RedirectMatch 301 ^(.*)$ https://www.yoursite.com
Redirect Old Website to New Website
An old website can be fully redirected to a new website, while keeping traffic and ranking, using:
RewriteCond %{HTTP_HOST} !^yournewdomain\.com
Rewrite Rule ^(.*)$ https://www.yournewdomain.com/$1 [R=301,L]
Complicated 301 Redirects in Apache
In some instances, it may be necessary to perform a little bit more complicated redirects. For example, if you want to redirect multiple pages to a single page or need to redirect while changing the file name. If this is the case, the code will be a little more extensive, but you will still use the same opening attributes:
Options +FollowSymLinks
RewriteEngine on
Redirecting Multiple Pages to One Page
Moving all of your link requests from an old site to one location, such as a new homepage, will require you to move the content on a page-by-page basis. Use the following code to perform this action:
Redirect 301 /oldsite1.htm https://www.yournewsite.com
Redirect 301 /oldsite2.htm https://www.yournewsite.com
Redirect 301 /oldsite3.htm https://www.yournewsite.com
Redirect 301 /oldsite4.htm https://www.yournewsite.com
Changing Filename with a Redirect
You can use a php extension to redirect all of the old files from one account that end with html to one file on a new account. You can also use this method if you want to change all of your extensions without losing any incoming links from old pages with the following code:
RedirectMatch 301 (.*)\.html$ https://www.yoursite.com$1.php
Redirecting CMS But Keeping Database
It is possible to change your site’s CMS while keeping your old database with a 301 redirect. To do this use:
RedirectMatch 301 /old cart.php(.*) https://www.yournewsite.com/newcart.php$1
Finally, upload the updated file to your root file. Don’t forget to test your new redirect to ensure they are working correctly. It’s also a important to check using the HTTP Header viewer to ensure it shows the correct 301 redirect.
CPanel Redirects
Some cPanels simplify the 301 redirect process. If this is the case, you’ll simply need to look for “Redirects” under Site Management while logged into your cPanel. In the first option, you’ll list your current directory. Then, add your new directory to the second box. Choose 301 for a permanent redirect, select to add the redirect, and you’re finished.
PHP 4 and PHP 5 Redirects
You’re able to use a PHP redirect to permanently move a website or single page to a new site. These redirects will tell browsers and search engines that the page has been moved to a new location.
<?php
header(‘HTTP/1.1 301 Moved Permanently’)
header(‘Location: https://www.yournewsite.com/’)
Active Server Pages
Active Server Pages (ASP) redirects will set the location header with the status code to be manually defined using:
<%
Response.Status-”301 Moved Permanently”
Response.AddHeader=‘Location’,”https://www.yournewsite.com/
404 Errors
Despite what you may have heard, do not use rel-canonical in place of a 301 redirect as it’s designed to resolve multiple URL issues. Instead, the best option to keep Google happy and to prevent 404 errors is to stick with a 301 redirect. 301 redirects are the ideal method to use to maintain SEO should you have redesigned your website, need to rid duplicate content, resolve multiple domain issues, or change domain names. However, if not performed correctly, users will receive a 404 error. To reduce the chance of an error, make sure you fully test your redirects and use the appropriate code pertaining to your website. There are many uses for the rel canonical and if a 301 cannot be performed it is generally the next best option. We always stay away from robots.txt files and URL parameters in Webmaster Tools if possible, in almost all cases a 301 or rel canonical is a better way to solve the issue.
Sources:
“Redirect” Moz.com