06-24-2010, 06:30 PM
In this tutorial I will be going through the .htaccess file that can really keep your site secure and safe. I hope you enjoy reading and feedback and comments are always welcome so please reply below.
Index - Sections
What is .htaccess?
.htaccess is a file that is run on an Apache server. The Apache server will read your .htacces file which will allow you to configure and customize the way your site appears to normal users with custom commands.
URL Redirection
This is really quite easy to implicate and simple to grasp. Please look at how to do it below:
SYNTAX -EXAMPLE -
Protecting Folders/Directories
This is again quite simple and is fantastic in my opinion, please read below:
SYNTAX - (One File!)SYNTAX - (Directory!)
Blocking Specific Users
This is a great way to stop users viewing your site all together. Makes it so they can't access or view any feature. You can also stop domains from viewing!
Here we have two main commands, 'deny' and 'allow'. Simply interchange as you wish.
SYNTAX -EXAMPLE
Set Server Timezone
This isn't vital but I think it's useful:
SYNTAX -EXAMPLE -
Stop Script Execution
This command will stop certain script types from being executed on your site. Really good to stop upload such as shells or viruses
SYNTAX -EXAMPLE -
Protect your .htaccess
This command will protect your .htaccess file from any unauthorized people accessing it:
SYNTAX -
This now concludes my .htaccess tutorial. If this helped or if you have any feedback then please comment below.
Regards,
- Sam
Index - Sections
- URL Redirection
- Changing Error Pages
- Protecting folders and directories
- Blocking specific users from your site
- Set server time zone
- Stop Script Execution
- Secure your .htaccess
What is .htaccess?
.htaccess is a file that is run on an Apache server. The Apache server will read your .htacces file which will allow you to configure and customize the way your site appears to normal users with custom commands.
URL Redirection
This is really quite easy to implicate and simple to grasp. Please look at how to do it below:
SYNTAX -
Code:
Redirect [Virtual URL to be redirected [Full or exact URL you want to redirect too]
Code:
Redirect /olddir/file.html http://yoursite.com/newdi/file.html
Protecting Folders/Directories
This is again quite simple and is fantastic in my opinion, please read below:
SYNTAX - (One File!)
Code:
<Files secure.php>
AuthType Basic
AuthName “Password Required”
AuthUserFile /home/path/.htpasswd
Require valid-user
</Files>
Code:
resides
AuthType basic
AuthName “This directory is protected please leave”
AuthUserFile /home/path/.htpasswd
AuthGroupFile /dev/null
Require valid-user
Blocking Specific Users
This is a great way to stop users viewing your site all together. Makes it so they can't access or view any feature. You can also stop domains from viewing!
Here we have two main commands, 'deny' and 'allow'. Simply interchange as you wish.
SYNTAX -
Code:
order allow,deny
deny from 111.82.3.1
deny from 182.45.1.8.
allow from all
Code:
order allow,deny
deny from 123.45.6.7
deny from www.google.com
allow from all
Set Server Timezone
This isn't vital but I think it's useful:
SYNTAX -
Code:
SetEnv TZ [Location]
Code:
SetEnv TZ America/Las_Vegas
Stop Script Execution
This command will stop certain script types from being executed on your site. Really good to stop upload such as shells or viruses
SYNTAX -
Code:
Options -ExecCGI
AddHandler cgi-script [file extension or file extensions separated with spaces]
Code:
Options -ExecCGI
AddHandler cgi-script .pl .py .php .jsp .htm .shtml .sh .asp .cgi
Protect your .htaccess
This command will protect your .htaccess file from any unauthorized people accessing it:
SYNTAX -
Code:
<Files .htaccess>
order allow,deny
deny from all
</Files>
This now concludes my .htaccess tutorial. If this helped or if you have any feedback then please comment below.
Regards,
- Sam
Spoiler (Click to View)
This tutorial is not 100% mine and nor will I claim it is. I compiled this tutorial in my own words and I added my own knowledge combined with some codes from other sites that have helped me along the way. Sources: http://www.askapache.com/htaccess/