What is .htaccess file?

123,497

Solution 1

It's not part of PHP; it's part of Apache.

http://httpd.apache.org/docs/2.2/howto/htaccess.html

.htaccess files provide a way to make configuration changes on a per-directory basis.

Essentially, it allows you to take directives that would normally be put in Apache's main configuration files, and put them in a directory-specific configuration file instead. They're mostly used in cases where you don't have access to the main configuration files (e.g. a shared host).

Solution 2

.htaccess is a configuration file for use on web servers running the Apache Web Server software.

When a .htaccess file is placed in a directory which is in turn 'loaded via the Apache Web Server', then the .htaccess file is detected and executed by the Apache Web Server software.

These .htaccess files can be used to alter the configuration of the Apache Web Server software to enable/disable additional functionality and features that the Apache Web Server software has to offer.

These facilities include basic redirect functionality, for instance if a 404 file not found error occurs, or for more advanced functions such as content password protection or image hot link prevention.

Whenever any request is sent to the server it always passes through .htaccess file. There are some rules are defined to instruct the working.

Solution 3

Below are some usage of htaccess files in server:

1) AUTHORIZATION, AUTHENTICATION: .htaccess files are often used to specify the security restrictions for the particular directory, hence the filename "access". The .htaccess file is often accompanied by an .htpasswd file which stores valid usernames and their passwords.

2) CUSTOMIZED ERROR RESPONSES: Changing the page that is shown when a server-side error occurs, for example HTTP 404 Not Found. Example : ErrorDocument 404 /notfound.html

3) REWRITING URLS: Servers often use .htaccess to rewrite "ugly" URLs to shorter and prettier ones.

4) CACHE CONTROL: .htaccess files allow a server to control User agent caching used by web browsers to reduce bandwidth usage, server load, and perceived lag.

More info : http://en.wikipedia.org/wiki/Htaccess

Solution 4

You are allow to use php_value to change php setting in .htaccess file. Same like how php.ini did.

Example:

php_value date.timezone Asia/Kuala_Lumpur

For other php setting, please read http://www.php.net/manual/en/ini.list.php

Solution 5

Htaccess is a configuration file of apache which is used to make changes in the configuration on a directory basis. Htaccess file is used to do changes in functions and features of the apache server. Htaccess is used to rewrite the URL. It is used to make site address protected. Also to restrict IP addresses so on particular IP address site will not be opened

Share:
123,497
Deepu
Author by

Deepu

Full stack web developer with experience in php,javascript,jquery,html,mysql,Zend, Laravel, Codeigniter, Agile, Nodejs etc.. profile for 웃웃웃웃웃 on Stack Exchange, a network of free, community-driven Q&A sites http://stackexchange.com/users/flair/1570947.png

Updated on July 09, 2022

Comments

  • Deepu
    Deepu almost 2 years

    I am a beginner to Zend framework and I want to know more about the .htaccess file and its uses. Can somebody help me?

    I found an example like this:

    .htacess file

    AuthName "Member's Area Name"  
    AuthUserFile /path/to/password/file/.htpasswd  
    AuthType Basic  
    require valid-user  
    ErrorDocument 401 /error_pages/401.html  
    AddHandler server-parsed .html  
    
  • Koray Tugay
    Koray Tugay over 11 years
    How is image hotlink prevented?
  • William Ross
    William Ross over 7 years
    Was wondering what is meant by passes through the .htaccess file?
  • Deepak Mahakale
    Deepak Mahakale about 6 years
    Adding the link for current version httpd.apache.org/docs/2.4/howto/htaccess.html