44

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  
웃웃웃웃웃
  • 11,829
  • 15
  • 59
  • 91
  • If you want to learn about `htaccess` and `URL rewriting` you can follow the easy tutorial here https://helponnet.com/2021/04/15/htaccess-tutorial-for-beginers – Amit Verma Aug 20 '21 at 07:09
  • All you need are the htpasswd tools and htaccess guide at https://www.askapache.com/htaccess/ – AskApache Htaccess Mar 22 '23 at 03:25

9 Answers9

66

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).

Amber
  • 507,862
  • 82
  • 626
  • 550
24

.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.

HIRA THAKUR
  • 17,189
  • 14
  • 56
  • 87
Amit Garg
  • 3,867
  • 1
  • 27
  • 37
14

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

Suresh Kamrushi
  • 15,627
  • 13
  • 75
  • 90
2

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

Danny Hong
  • 1,474
  • 13
  • 21
2

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

1

What

  • A settings file for the server
  • Cannot be accessed by end-user
  • There is no need to reboot the server, changes work immediately
  • It might serve as a bridge between your code and server

We can do

  • URL rewriting
  • Custom error pages
  • Caching
  • Redirections
  • Blocking ip's
Hasan Gökçe
  • 501
  • 6
  • 6
0

You can think it like php.ini files sub files.. php.ini file stores most of the configuration about php like curl enable disable. Where .htaccess makes this setting only for perticular directory and php.ini file store settings for its server' all directory...

Dharmik
  • 2,325
  • 3
  • 27
  • 37
0

It is not so easy to give out specific addresses to people say for a conference or a specific project or product. It could be more secure to prevent hacking such as SQL injection attacks etc.

0

.htaccess file create in directory /var/www/html/.htaccess

<IfModule mod_rewrite.c>

RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]
</IfModule>
Amit Sharma
  • 1,775
  • 3
  • 11
  • 20