What is .htaccess file?
A .htaccess file is an ASCII file. It is a short form of Hypertext Access. It is a configuration file used by Apache-based web servers. The .htaccess is the file’s extension. It is not a file name. It will affect on the folder in which it is located and also on subfolders.
we can use .htaccess for following
Create .htaccess file in root of your project and add following code in it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Before URL is like www.example.com/home.php
After adding .htaccess it will be like www.example.com/home
Redirect to custom error pages
A .htaccess file is an ASCII file. It is a short form of Hypertext Access. It is a configuration file used by Apache-based web servers. The .htaccess is the file’s extension. It is not a file name. It will affect on the folder in which it is located and also on subfolders.
we can use .htaccess for following
- Remove file extension
- Redirect to custom error pages
- Block or allow IP addresses
- Prevent directory listings
Create .htaccess file in root of your project and add following code in it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}\.php -f
RewriteRule ^(.*)$ $1.php
Before URL is like www.example.com/home.php
After adding .htaccess it will be like www.example.com/home
Redirect to custom error pages
It is used to redirect the user to a custom error page by using the error code.
Following are error codes
- 400 – Bad request
- 401 – Authorization Required
- 403 – Forbidden
- 404 – File Not Found
- 500 – Internal Server Error
ErrorDocument 404 /path/404.php
ErrorDocument 505 /path/505.php
Block or allow IP address
order allow,deny
deny from 192.168.1.1
allow from 192.168.1.2
Prevent directory listings
.htaccess also used to prevent folders to access directly by an end user.
Options All -Indexes
Block or allow IP address
order allow,deny
deny from 192.168.1.1
allow from 192.168.1.2
Prevent directory listings
.htaccess also used to prevent folders to access directly by an end user.
Options All -Indexes
Comments
Post a Comment