htaccess in 10 minutes

Share It!

We always stuck when it comes to make change in .htaccess file. I always confusing. Here you can see htaccess in 10 minutes.


1) What is .htaccess?

.htaccess is more than a file which has ability to perform following things

1) Handling redirects
2) Handling Erros
3) Password protection
4) Add MIME Types
5) Block/Deny visitor by IP or Referrer
6) Directory listing block
7) Server timezone change
8) Server performance tuning
9) Secure configuration files
10) Block browser and bots

2) How to use .htaccess?

First of all create new file. “.htaccess” file is it self a name it is not a file type or extension. If you are not able to create it in window system then create file name htaccess.txt and then upload it to server using file zilla or cuteFTP. Make sure that your .htaccess file encoding type set to ASCII. Set permission to 0755 using FTP program.
If you are not aware about your server details or issue with creating .htaccess file the please contact your system administrator

Note: Put your newly created .htaccess file to you website document root. e.g /usr/local/apache2/htdocs/ OR /var/www/public_html etc.

3) Error Handling using .htaccess

Error handling is very helpful and useful for website visitor to give some proper message about error. How to handle error in .htaccess. Here is the way for the same
Most of the time we have facing issue like, page not available or file/page deleted. What to do in this error case. In terms of server error it throws error code 404 page not found. We – Technical person know this code 404 page not found what about non-technical person. So we need to handle 404 error code using .htaccess by as follows.
– Create page name pagenotfound.html and put some friendly message in it. So visitor can easily understand it.
– Open your newly created .htaccess file and copy paste code to .htaccess file
ErrorDocument 404 /pagenotfound.html

You can add more error code as per your requirement like 500 internal server error, 502 bad gateway error, 401 error code like way.. Just change the error code in above line with your one and change file name as per your needs.

4) Website protection with .htaccess

Some time we need to block some visitors by IP. You can do this by following

order allow,deny
deny from
deny from 123.45.6.
allow from all

5) Redirects using .htaccess

Example- Redirect to

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

Example 2- Redirect to

RewriteEngine on
RewriteCond %{HTTP_HOST} ^www\.techoism\.com$
RewriteRule ^/?$ "http\:\/\/techoism\.com\/" [R=301,L]

6) Useful with .htaccess

Redirecting with Joomla

In Joomla you can copy and past below code to .htaccess file

# For security reasons, Option followsymlinks cannot be overridden.
#Options +FollowSymLinks
Options +SymLinksIfOwnerMatch

Happy Techoisming….

Leave a Reply

Your email address will not be published.