Create a 301 Redirect with .htaccess

One of the advantages of using WordPress is the abundance of free plugins. One of the disadvantages of using WordPress is the abundance of free plugins. The greater the number of plugins running on your site the greater the chance of slowing it down. Since Google uses page speed as a ranking factor I’ve decided to cut back on the number of plugins I use on my sites. You should too.

In the past when I needed to create a 301 redirect I used a plugin named Redirection. It’s a great plugin and it always did what was needed. But as I mentioned above, the more you have the more you need to think about what you can do without using a plugin. Performing 301 redirects is something you can do without needing yet another plugin.

Now, all of my sites use the .htaccess file to perform 301 redirects. If you find yourself in need of performing 301 redirects on your WordPress site, check out just how easy it is from my examples below.

MAKE A BACKUP OF .HTACCESS BEFORE MAKING ANY EDITS!
Even the slightest syntax error (like a missing space) can result in your website exploding!

.htaccess Code Samples

Point an entire site to a different URL, such as rvamedia.net redirected to rvamedia.com:

##
# This allows you to redirect your entire website to any other domain
#
# @author: Rick R. Duncan
# @link: http://www.buildbrandbelieve.com
# #
redirect 301 / http://www.rvamedia.com/

Redirect index.php to a specific subfolder:

##
# This allows you to redirect index.php to a specific subfolder
#
# @author: Rick R. Duncan
# @link: http://www.buildbrandbelieve.com
# #
redirect 301 /index.php http://www.rvamedia.com/newdirectory/

Redirect an old file to a new file path:

##
# Redirect old file path to new file path
#
# @author: Rick R. Duncan
# @link: http://www.buildbrandbelieve.com
# #
redirect 301 /olddirectory/oldfile.html http://www.rvamedia.com/newdirectory/newfile.html

If for some reason you didn’t make a backup of your .htaccess file, here is a fresh copy for WordPress.

##
# .htaccess clean slate (start over)
#
# @author: Rick R. Duncan
# @link: http://www.buildbrandbelieve.com
# #
# BEGIN WordPress
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
# END WordPress

Leave a Comment

*