How to Do 301 Redirect in htaccess

WordPress, Joomla, Magento, ZenCart, OsCommerce, VBulletin etc are most commonly used PHP applications. If your website is based on any of these opensource scripts or else it’s a custom PHP application, you need Apache Server to run the scripts. Apache Servers normally work with Linux hosting, but can be installed on Windows hosting too.

This tutorial will guide you on redirecting following URLs to using htaccess on Apache servers.



  • 1

    Make sure that your hosting service has provided you with Apache Server in case you’re on Windows hosting, else skip this step.

  • 2

    Confirm that Apache Rewrite Module is turned on. On Linux servers, it’s turned on by default, but in case if it’s not, you’ll need to ask the hosting company. If you’re an advance user and have access to the httpd.conf file, you can turn the module on yourself. To do so, first take backup of httpd.conf file and then uncomment the following line:

    LoadModule rewrite_module modules/

    Save the file and restart the server.

  • 3

    Login to your FTP and Download .htaccess file which is located at the root web folder.

  • 4

    Save a copy of .htaccess file somewhere else for backup purpose and then open the current file for editing. It’ll open in notepad.

  • 5

    Add the following code to .htaccess file. Replace “” with your own website and do not change anything else.

    RewriteEngine On
    RewriteBase /

    Redirect 301

    Redirect 301

    Redirect 301

    RewriteCond %{HTTP_HOST} ^
    RewriteRule (.*)$1 [R=301,L]

  • 6

    Now save the file.

  • 7

    Upload edited file back to the location from where it was downloaded.

  • 8

    Once uploaded, type each URL to verify if it’s working or not. If working, it should redirect immediately.

  • 9

    To cross verify, visit and enter your URL. It should display all the results as 301 moved to the www version of your domain else at the end of processing it gives you additional feedback too.

  • 10

    If it’s still not working, copy the backed up .htaccess file and start from the beginning and see you might have missed some instructions.

Leave a Reply

Your email address will not be published. Required fields are marked *

2 × three =