How To Use .Htaccess

Posted by Ilyas online blog


Htaccess is a configuration file provided by the Apache web server, which is usually used to change the default settings of Apache. We know that the majority of web hosting on the internet using Apache as the server so that the web administrators / webmasters have to learn a little more about. Htaccess so that we can change the default settings of the server. Files. Htaccess is a simple ASCII text file which is usually located in the root directory. Is required to file in ASCII format instead of binary and to file permissions (file attributes) on the hosting server should be set to 644 (rw-rr). It is intended that the server can access the file. Htaccess, but prevents the user to access the file. Htaccess from their browser. Files. Htaccess is placed in the root directory can be used to change the configuration of the subdirectories in it, so in one website we usually sufficient to have 1 file. Htaccess are placed in the root directory.

Command code in the .Htaccess should be placed in a row, so when we create .Htaccess by using a text editor like notepad then we have to disable word wrap function (line cut) first.


.Htaccess can be used to :

1. Custom Http Error 
Error message on a website is very important because it can help the visitors to find out what was going on. With htaccess we can turn the page on a server error, by defining our own liking. An example is the transfer of messages according to their function as follows:

ErrorDocument 400 /errors/400.html 
ErrorDocument 401 /errors/401.html 
ErrorDocument 403 /errors/403.html 
ErrorDocument 404 /errors/404.html 
ErrorDocument 500 /errors/500.html


2. Override Ssl Setting


By default, only the web pages that have the extension. Shtml that can run server-side includes SSI on the server. By using the. Htaccess we can change the default setting so that SSI can work with HTML format.
To change these settings, we can add the following code in the file. Htaccess

AddType text/html .html 
AddHandler server-parsed .html

If we want a page with extension. Html and. Htm to be able to run SSI, then the file. Htaccess you can add the following code

AddType text/html .html 
AddHandler server-parsed .html
AddHandler server-parsed .htm

3. Change Default HomePage

It means that . htaccess can be used to change the default name of the web page. So that users can access our website only with domain name only (http://www.Your-web.com) without having to write clearly filename (http:Your-web.com/file.html), we must have index file in the root directories. Acceptable file names such as index.html, index.htm, index.cgi, index.php etc.. Make sure that the file named index. *

There are levels in the naming. If we had index.cgi index.html in the root directory and the server will display index.cgi since. Cgi has a higher level than. Html
With. Htaccess, we can define an additional index file or can also change the order of precedence. To define mainpage.html as index pages, we can add the following code to the file. Htaccess

DirectoryIndex mainpage.html


4. Block User From IP Address

order deny,allow
deny from 123.456.789.000 
deny from 456.78.90.
deny from .facebook.com
allow from all 


5. Rewriting Urls

RewriteEngine On 
RewriteBase / RewriteCond %{REQUEST_FILENAME} !-f 
RewriteCond %{REQUEST_FILENAME} !-d 
RewriteRule . /index.php [L] 

6. Cache Control

# 480 weeks Header set Cache-Control "max-age=290304000, public" 
# 2 DAYS Header set Cache-Control "max-age=172800, public, must-revalidate"
# 2 HOURS Header set Cache-Control "max-age=7200, must-revalidate"



Related Post



Post a Comment