What is .htaccess in PHP?

WBOY
Release: 2023-08-27 17:02:02
forward
894 people have browsed it

What is .htaccess in PHP?

.htaccess is a configuration file for use on web servers running on the web apache server software. when a .htaccess file is placed in a directory which in turn loaded via the Apache web server, then the .htaccess file detected and executed by the Apache server software.

.htaccess files can be utilized to modify the setup of the Apache server software to empower additional functionality and fetures that the apache web server softwatre brings to the table. We can use the .htaccess file for various alteration configuration in apache web server software. Some of them are listed below:

ErrorDocuments

Creating custom error pages is very useful, it allows us to show web site visitors a friendly error message, in case of if a URL on your web site does not work.

ErrorDocument 404 /error_pages/404.html
Copy after login

Password Protection

It is very easy, we can password protect the application directory that requires username and password to access.

AuthName "Admin Area"
AuthUserFile /path/to/password/file/.htpasswd
AuthType Basic
require valid-user
Copy after login

The first line tells the Apache web server that the security directory is called the 'Admin Area' and this will be displayed when the pop-up login prompt appears. The following line indicates the location of the password file. The third line determines the authentication type, in this example we're using 'Basic' since we're using basic HTTP authentication, and finally the fourth line says we need valid login credentials

Redirect

Redirects allow us to redirect website visitors from one document to another within the website.

Redirect /old_dir/ http://www.test.com(your domain)/new_dir/index.html
Copy after login

Deny visitors based on IP address

order allow,deny
deny from 155.0.2.0
deny from 123.45.6.1
allow from all
Copy after login

The above lines tell the Apache Web Server to block visitors from the IP address '155.0.2.0' and '123.45.6.1' and allow all other IP addresses.

Adding MIME types

To set up a MIME type, create a .htaccess file following the main instructions and guidance which includes the following text:

AddType text/html htm0
Copy after login

'AddType 'Make sure you are including a MIME type. The subsequent part is the MIME type, in this case content or HTML, and the last part is the file extension, in this case 'htm0'.

The above is the detailed content of What is .htaccess in PHP?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template