Go Back   Web Server Hosting Forum by BODHost > Support > Linux Server Hosting
 

Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old 12-04-06, 09:28
BOD Member
 
Join Date: Jul 2006
Posts: 107
Default Usage of .htaccess

What they are/How to use them

.htaccess files (or "distributed configuration files") provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.

Note: If you want to call your .htaccess file something else, you can change the name of the file using the AccessFileName directive. For example, if you would rather call the file .config then you can put the following in your server configuration file (httpd.conf):

AccessFileName .config

The first of these is performance. When AllowOverride is set to allow the use of .htaccess files, Apache will look in every directory for .htaccess files. Thus, permitting .htaccess files causes a performance hit, whether or not you actually even use them! Also, the .htaccess file is loaded every time a document is requested.



Some of the Important and useful function, .htaccess can do is as follows.

1) Setting default index page for any particular domain/site:
To customize the default index page for any site put following line in .htaccess file with the file name you want as default page.

Code:
--------------------------------------------------
DirectoryIndex filename.html
--------------------------------------------------
Replace the filename with your default home page.


2) Redirecting with the help of .htaccess
Add following line in .htaccess file in the directory you want to redirect to somewhere else.

Code:
--------------------------------------------------
RedirectMatch .* http://domainname/PathToFile
--------------------------------------------------

3) Customize Error document with .htaccess.

Add following in your sites DocumentRoot to take the error page from within errors folder in DocumentRoot.

Code:
--------------------------------------------------
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
--------------------------------------------------

4) Avoiding Directory listing
If default index page is not created the apache server by default shows Directory Listing to avoid this create an empty file named as index.html or index.php or add following code in your .htaccess.

Code:
--------------------------------------------------
IndexIgnore * # > for avoiding listing of all files
IndexIgnore *.gif *.jpg # > for avoiding listing of only particular type of file.
Options Indexes # > Deny directory listing completely. [Only site name appear]
--------------------------------------------------



5) Blocking users by IP With the help of .htaccess

Is there a pesky person perpetrating pain upon you? Stalking your site from the vastness of the electron void? Blockem! In your htaccess file, add the following code--changing the IPs to suit your needs--each command on one line each:

Code:
--------------------------------------------------
order allow,deny
deny from 123.45.6.7
deny from 012.34.5.
allow from all
--------------------------------------------------

You can deny access based upon IP address or an IP block. The above blocks access to the site from 123.45.6.7, and from any sub domain under the IP block 012.34.5. (012.34.5.1, 012.34.5.2, 012.34.5.3, etc.) I have yet to find a useful application of this, maybe if there is a site scraping your content you can block them, who knows.
=================================================


6) execute cgi script out of cgi-bin directory

The apache treat cgi scripts as stated in httpd.conf in ScriptAlias directory i.e. cgi-bin. To execute cgi script outside cgi-bin just adds following 2 lines in .htaccess files to execute cgi scripts in any folder outside cgi-bin.

Code:
--------------------------------------------------
AddHandler cgi-script .pl .cgi
Options Includes ExecCGI
--------------------------------------------------

7) Trailing Slash problem:

Put this in .htaccess in your document root (given example is for my site of course, replace the server name with yours)

Code:
--------------------------------------------------
RewriteEngine on
RewriteBase /
RewriteCond %{REQUEST_FILENAME} -d
RewriteRule ^(.+[^/])$ http://etechsupport.net/$1/ [R]
--------------------------------------------------

8) Changing the php directive/setting with the help of .htaccess
To change the php directive/setting add following in .htaccess file in your DocumentRoot.

Code:
--------------------------------------------------
php_flag register_globals on
php_value register_globals off
php_value max_execution_time 60
php_value upload_max_filesize 16777216
php_value post_max_size 16777216
--------------------------------------------------
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off
Forum Jump


All times are GMT -6. The time now is 00:14.

Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
Copyright © 1999-2012, BODHost Ltd. All rights reserved.