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:
- RewriteEngine On
- RewriteCond %{HTTPS} !on
- 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:
- php_value upload_max_filesize 10M
- php_value post_max_size 10M
- php_value max_execution_time 200
- php_value max_input_time 200