.htaccess is used very common nowadays. To create the .htaccess file you can open notepad and save the file with name of .htaccess.

htaccess tricks

htaccess tricks

So here are some popular htaccess tricks.

If you want that if you type example.com in your url and it is changed to http://www.example .com then you can do this by writing the following code in .htaccess file:-

RewriteCond %{HTTP_HOST} ^example\.com$ [NC]

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

This is good for seo point of view because example.com and http://www.example.com are two different url for search engines.

If you want to show all the files in the directory if there is also index.html or index.php exists in the directory then you write the code as follows:-

Options +Indexes

IndexOptions FancyIndexing

Suppose there is no index.php file in your directory and there is a file home.php and if want that home.php will open as default page then you can do this as:-

DirectoryIndex home.php

For hiding files like you want to hide the files with extension of .txt and .ico then write the code as:-

IndexIgnore *.txt *.ico

If you have a file with your own extension of .jon and you want that file to open as php file then do write this code in .htaccess file

AddType application/x-httpd-php .jon

If you want to restrict some file from viewing then you can also do this in .htaccess file. Suppose you want to restrict myfile.txt then here the code:-

<files myfile.txt>
  order allow,deny
  deny from all
</files>

Don’t place space between allow and deny

If you want to restrict all the file of extension .txt and .ico then write this code:-

<FilesMatch "\.(txt|ico)$">
  order allow,deny
  deny from all
</FilesMatch>

If you want add default char set then here u can do this:-

AddDefaultCharset utf-8

Related Posts

Tagged with:
 

Leave a Reply

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

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Looking for something?

Use the form below to search the site:


Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!

Visit our friends!

A few highly recommended friends...

Set your Twitter account name in your settings to use the TwitterBar Section.