Monday, 11 January 2016

Useful commands to use .htacess

Redirect /old_dir/ http://www.yourdomain.com/new_dir/index.html

this command redirect the user visiting to the old_dir to the site http://www.yourdomain.com/new_dir/index.html.

DirectoryIndex index.html

this command directs the server to serve the index.html file when the directory in which .htaccess file is residing, is accessed

AddType application/octet-stream .bin .exe 

this command force the browser to save the files having the extension .bin & .exe

SSI stands for Server Side Includes. Inside an html file, we can include another html or cgi file using SSI. These things usually happens with shtml file. But to make it happen with .html files. We use the command shown below:

<!--#include virtual="/files/document.html"--> 

This url is relative

IndexIgnore *.zip *.jpg *.gif

This command does not let the zip, jpg and gif files appear in the directory listing

Options +Indexes
allows the web apache serve to enable directory listing

Options -Indexes
disable the directory listing


If you have a directory containing PHP includes, that you do not wish to be accessed directly from the browser, there is a way of disabling the directory using Mod_Rewrite.

To enable this, create a .htaccess file following the main instructions and guidance, and include the following text:
## Enable Mod Rewrite, this is only required once in each .htaccess file
RewriteEngine On
RewriteBase /
## Test for access to includes directory
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /includes/ .*$ [NC]
## Test that file requested has php extension
RewriteCond %{REQUEST_FILENAME} ^.+\.php$
## Forbid Access
RewriteRule .* - [F,NS,L]


Where /includes/ is your includes directory.