htaccess redirect thumb

This article will inform you better on how easy is to make htaccess redirect on your website. Htaccess file is a very powerful configuration file which normally can be found in root folder of your domain . In case that you that you are unable to see it please check your FTP client preferences and set it to display hidden files.

Htaccess is actually configuration file and its been used on servers operated by Apache software and when is being read by Apache Web Server software in root directory of your domain htaccess file enable or disable additional functions and features offered by your web server.

Once when you found htaccess file and download the it from the server you can edit and change them in any standard text editor like Notepad, TextPad, Microsoft Word. It is important to remember that .htaccess file doesn’t have any additional extension like .php, .html or similar its just text file and call it just “.htaccess”.

Once when its been modified and uploaded in root directory of your domain all changes made by you will reflect on entire directory and and contained folders.The most common usage of this server file is for creation of htaccess redirect on your website and in accordance with that we will reveal you most frequent types of htaccess redirections.

Htacces redirect from index.html or index.php to main domain

RewriteEngine On
RewriteBase /
# redirect html or php pages to the root domain
RewriteRule ^index\.html$ / [NC,R,L]

Redirection from non to www version

RewriteEngine On
RewriteCond %{HTTP_HOST} ^domainname.com$
RewriteRule (.*) http://www.domainname.com/$1 [R=301,L]

Permanent 301 htaccess redirect from http to https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]

Temporarely 302 htaccess redirect from http to https

RewriteEngine On
RewriteCond %{HTTPS} off
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [R=302,L]

Permanent 301 redirection from old to new domain

RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^olddomainname\.com$ [NC]
RewriteRule ^(.*)$ http://newdomainname.com [R=301,L]

to make redirect to specific pages from old to new domain add this:

RewriteEngine On
RewriteRule ^(.*)$ http://www.newdomain.com/$1 [R=301,L]

Redirect your main domain into subdirectory

RewriteEngine On
RewriteCond %{HTTP_HOST} ^(www.)?YourDomain.com$
RewriteRule ^(/)?$ blog [L]

For easiest way to redirect your main domain into subdomain for example folder “shop” is by adding two bottom lines in .htacces file and as a result you will get search engine friendly link which will look in our case like this: http://www.shop.domainname.com.

For the end, be very cautious while you editing htaccess because even the smallest mistake can cause that your website will not be shown. In next chapter we will introduce you some more advanced features of htaccess file like password protection, blocking ip, prevention of image hot linking, enabling Gzip compression etc.