Hypertext access is shortly called as htaccess. It is a directory level configuration file. Directory level means, where you locate your .htaccess file, it configure that directory only. Mostly, on server, it is placed on public_html folder for configure the files to access. You can control your site using it. It is supported by web servers.
- DirectoryIndex uses
- used for restrict the user for access pages from website
- redirect the urls
- gives direction to server rather than search engine
- create error document
- compressing resources with gzip
- add expires headers
- enable and disable the additional functionality of apache webserver
- prevent access to php.ini file
- force scripts to display as a source code
- ensure media files are downloaded instead of played
Syntax:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-l
RewriteBase /
DirectoryIndex index.php
RewriteRule ^home index.php [L]
</IfModule>
Explanation:
<IfModule mod_rewrite.c>
IfModule test whether mod_rewrite.c is included in apache. If mod_rewrite.c
is included, then it run. Otherwise it doesn't get run.
RewriteEngine On
It tells apache to turn on its RewriteRules.
RewriteCond
RewriteCond execute the next rewrite rules if it is correct.
%(REQUEST_FILENAME) is a variable based on url you request
!-f, !-d, !-l are extension added to regular expression.
where,
!- f - rewrite condition if it is not file
!-d - rewrite condition if it is not directory
!-l - rewrite condition if it is not link
if a file, taken from variable %(REQUEST_FILENAME) does not exist on the file system, then return true.
RewriteBase /
It provide base for RewriteRules.
DirectoryIndex index.php
It tells apache to which file is run first when server access to particular directory.
RewriteRule
It redirect the urls.
RewriteRule ^home index.php [L]
it means, when url get ' home ' on address bar, it runs the file index.php. Using this method, we can change our address bar contents to anything.
For example,
RewriteRule ^sample.html sample.php [L]
where,
you type sample.html in your address bar, the .htaccess runs sample.php file.
we can pass the values in address bar using it.
Related Post:
Uses of .htaccess:
- DirectoryIndex uses
- used for restrict the user for access pages from website
- redirect the urls
- gives direction to server rather than search engine
- create error document
- compressing resources with gzip
- add expires headers
- enable and disable the additional functionality of apache webserver
- prevent access to php.ini file
- force scripts to display as a source code
- ensure media files are downloaded instead of played
How to start with .htaccess?
Syntax:
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteCond %(REQUEST_FILENAME) !-f
RewriteCond %(REQUEST_FILENAME) !-d
RewriteCond %(REQUEST_FILENAME) !-l
RewriteBase /
DirectoryIndex index.php
RewriteRule ^home index.php [L]
</IfModule>
Explanation:
<IfModule mod_rewrite.c>
IfModule test whether mod_rewrite.c is included in apache. If mod_rewrite.c
is included, then it run. Otherwise it doesn't get run.
RewriteEngine On
It tells apache to turn on its RewriteRules.
RewriteCond
RewriteCond execute the next rewrite rules if it is correct.
%(REQUEST_FILENAME) is a variable based on url you request
!-f, !-d, !-l are extension added to regular expression.
where,
!- f - rewrite condition if it is not file
!-d - rewrite condition if it is not directory
!-l - rewrite condition if it is not link
if a file, taken from variable %(REQUEST_FILENAME) does not exist on the file system, then return true.
RewriteBase /
It provide base for RewriteRules.
DirectoryIndex index.php
It tells apache to which file is run first when server access to particular directory.
RewriteRule
It redirect the urls.
RewriteRule ^home index.php [L]
it means, when url get ' home ' on address bar, it runs the file index.php. Using this method, we can change our address bar contents to anything.
For example,
RewriteRule ^sample.html sample.php [L]
where,
you type sample.html in your address bar, the .htaccess runs sample.php file.
we can pass the values in address bar using it.
Related Post:
Restrict users to access pages from site using .htaccess
Compressing resource with gzip using .htaccess
How to create error document using .htaccess
How to add expires headers using .htaccess
How to add MIME types using .htaccess
How to enable SSI using .htaccess
How to force script to display as source code using .htaccess
How to prevent access to php.ini file using .htaccess
How to enable or disable directory list using .htaccess
How to redirect urls using .htaccess
How to redirect to www using .htaccess
How to enable short tag in php using .htaccess
How to access pages through one page in site using .htaccess
Compressing resource with gzip using .htaccess
How to create error document using .htaccess
How to add expires headers using .htaccess
How to add MIME types using .htaccess
How to enable SSI using .htaccess
How to force script to display as source code using .htaccess
How to prevent access to php.ini file using .htaccess
How to enable or disable directory list using .htaccess
How to redirect urls using .htaccess
How to redirect to www using .htaccess
How to enable short tag in php using .htaccess
How to access pages through one page in site using .htaccess
I'm very thank to you. Its very useful to me. Actually i got trouble in .htaccess. your post solved it. I need to know more about .htaccess.
ReplyDeleteThanks baba... Just join with blog., we'll discuss more about .htaccess
Deletethank you
ReplyDelete