If you have installed WordPress there is a high likelihood you have encountered the .htaccess file. The .htaccess file is a configuration file usually found on web servers running Apache. If you install WordPress on a cPanel server you are likely to find it in the public_html directory or your root directory.

The file is used for configuration of the apache server and can help you change a number of settings such as:

The above are the most common uses for the .htaccess file but it can be used to perform a number of advanced configurations as well.

If you need to change or edit the .htaccess file there are a number of ways to go about it. Depending on your hosting provider you can take a number of different approaches to edit it. The easiest and recommended method is via a great WordPress plugin: Htaccess Editor.

Installing the Plugin

The process for installing any plugin on WordPress is generally the same. Here is a detailed step by step guide.

1. Login to your WordPress dashboard on the left hand menu select plugins and click on Add new

To install a htaccess editor plugin

2. Search for Htaccess editor

Search htaccess editor plugin

3.      Install and activate the plugin

4.      To edit the .htaccess file go to tools on the left hand menu and click on WP Htaccess editor

activated htaccess editor plugin

The screen above will display the contents of your .htaccess file. Depending on what your goal is you can edit this file.

Setting Up 301 Redirects

One of the most common reasons for editing this file is to redirect a web page or an entire site. A 301 redirect is a permanent redirect from one link to another.

If you set this up correctly in your htaccess file, you will redirect visitors and search engines to a different link than the one they originally intended to visit. Here are 2 common reasons why website owners and marketers use 301 redirects:

  1. To improve search engine rankings and maximize domain authority. https://www.example.com and http://example.com may take you to the exact same page but in the eyes of search engine those are 2 different websites with duplicate content. Also notice one url has http and the other has https, you should always make sure your website visitors are protected by an ssl certificate.
  2. To rebrand or rename a website with a different URL. Supposing you change a company name from COMPANY-ABC to COMPANY-DEF what happens to your old website? You can simply redirect your old domain to your new one.

Here is an example of setting up a 301 redirect using the Htaccess editor plugin. Let us suppose you want to redirect http://yoursite.com/your-old-page.html  to http://yoursite.com/your-new-page.html

The simplest way to do this would be to add the following code to you .htaccess file.

Redirect 301 /your-old-page.html http://yoursite.com/ yoursite.com/your-new-page.html

insert 301 redirect in htaccess

Once you add the code click on save changes, when you visit http://yoursite.com/your-old-page.html you will be taken to http://yoursite.com/your-new-page.html

If you want to redirect an entire website then here is an example of the code you will need to add in your .htaccess file. This way does it with all URLs intact. That is www.yoursite.com/some/crazy/link.html will become www.yournewsite.com/some/crazy/link.html. This is extremely useful when you are just “moving” an entire website to a new domain. Place this on the OLD site:

Redirect 301 / http://yournewsite.com/


As mentioned earlier there are many ways to edit the .htaccess file and many other plugins are available as well. Editing the .htaccess file can easily make your website or page inaccessible. However this plugin is a safe way to edit the file as it automatically creates a backup of the file each time you edit it. The backups are time stamped for you to easily be able to identify which backup you would like to restore. There is an official forum with an active user community to help you should you get stuck somewhere.

This article introduced the steps of performing 301 redirects manually by editing your .htaccess, however, if you are not familiar enough with the codes, you can easily do it with one of these best free 301 redirect plugins.

PHP Code Snippets Powered By : XYZScripts.com