Home » Blogging, SEO Tips » .htaccess Redirection Guide

The Distributed Configuration Files, named as .htaccess, is the most reliable method to redirect webpages or even a website. This is the most secured and fastest redirection in some cases. Please note, this file works only with Apache installed on a Linux Server.

htaccess Redirect

htaccess Redirect

Here is complete guide on how to redirect webpages using .htaccess files. But, there’s something you should know..

  1. .htaccess files works only with Apache installed on Linux Servers
  2. You should put the .htaccess file in document root to make it work.
  3. Moving the configuration to httpd.conf file (if you have access to server’s main configuration file) will significantly improve the performance.
  4. 301 means the page is moved permanently while 302 means moved temporarily. 301 redirection also preserves backlinks and PR if there are any.

Let’s get started:

Redirect a single webpage

  • For a page that resides in same directory
    Redirect 301 /oldpage.html /newpage.html

    For a page that resides in a different directory (use absolute path if necessary)

    Redirect 301 /oldpage.html /new/folder/newpage.html

    For a page on different domain

    Redirect 301 /oldpage.html http://www.newdomain.com/newpage.html

Redirect an entire website

  • Place the .htaccess file in old domain’s document root
    Redirect 301 / http://www.newdomain.com/

Redirect domain.com to www.domain.com

  • This is to redirect the non www version of the website to the www version. Requires mod_rewrite to be installed.
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} ^yoursite.com [NC]
    RewriteRule ^(.*)$ http://www.yoursite.com/$1 [L,R=301]

Redirect www.domain.com to domain.com

  • This is to redirect the www version of the website to the non www version. Requires mod_rewrite to be installed.
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{HTTP_HOST} .
    RewriteCond %{HTTP_HOST} !^example\.com
    RewriteRule (.*) http://example.com/$1 [R=301,L]

Redirect index.php or the index.html to Domain Root

  • This is to force the document root as your website root. This is helpful to avoid duplicate homepage. Requires mod_rewrite to be installed.
    Options +FollowSymLinks
    RewriteEngine on
    RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /.*index\.php\ HTTP/
    RewriteRule ^(.*)index\.php$ /$1 [R=301,L]

Leave a Reply