what is .htaccess and how to use it

htaccess is the short form of Hypertext Access. It is a configuration file to control the directory it is placed and all the sub directories underneath it. you can redirect pages, override the server configuration, change the page extension, password protect the web pages and much more.

Following are the few tips to use the htaccess file for your website :

1. Force a file to download with a “Save As” prompt.

You can force a file to download instead of opening in browse, use this piece of code:

AddType application/octet-stream .doc .mov .avi .pdf .xls .mp4

2. Redirect to a secure https connection

If you want to redirect your entire site to a secure https connection, use the following:

  1. RewriteEngine On
  2. RewriteCond %{HTTPS} !on
  3. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}

3.Set up a 301 redirect

If you move around the structure of your site and need to redirect some old URLs to their new locations, the following bit of code will do so for you

Redirect 301 /original/filename.html http://domain.com/updated/filename.html

4. Set the default page of each directory

You can set the default page of the website if you don’t want to use an index page. The following code will do this

DirectoryIndex news.html

5.  Restrict file upload limits for PHP

You can restrict the maximum file size for uploading in PHP, as well as the maximum execution time. Just add this:

  1. php_value upload_max_filesize 10M
  2. php_value post_max_size 10M
  3. php_value max_execution_time 200
  4. php_value max_input_time 200

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.