UK WEB HOSTING FORUM FOR DISCUSSION ON WEB HOSTING SERVICE AND SUPPORT
LINUX HOSTING WINDOWS HOSTING PACKAGES SHOPPING CART OSCOMMERCE ZEN CART AGORA
ECOMMERCE HOSTING ASP MSSQL FRONTPAGE HOSTING PHP MYSQL HOSTING DISCUSSION FORUM
CPANEL RESELLER HOSTING DEDICATED SERVER VPS HOSTING PLESK VIRTUOZZO
Quick Search
Your forum announcement here!

  UK Web Hosting | Dedicated Server Windows and Linux VPS Forum > Technical Support > Linux Dedicated Servers

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 25-11-2006, 21:18
eUK-Scott's Avatar
System Administrator
 
Join Date: Oct 2006
Posts: 198
Wink Understanding htaccess

.htaccess (Hypertext Access) is the default name of Apache's directory-level configuration file. It allows webmasters to customize configuration directives, normally available in the main httpd.conf.

htaccess allows webmasters to do a range of customization to a webservers behaviour in a directory, including password protecting them, denying access, error handlers, redirects and a lot more. htaccess is particularly useful when you don't have root access to the server. For example, in virtual Web Hosting and ISPs.

Before making any of these configurations, however, the following points need to be kept in mind.

* Your webserver Administrator should allow you to make these changes by using ``AllowOverride All'' in the main configuration file(httpd.conf)
* You need to make sure that you are not using Microsoft Frontpage on your website hosting. Frontpage uses htaccess for its own directives. Changing the .htaccess files to insert new directives ``will'' break your website hosting.
* Test, Test, Test. Test new htaccess configurations on an empty directory before making it LIVE.

A .htaccess file controls the directory it is in, plus all subdirectories. However, by placing additional .htaccess files in the subdirectories, this can be overruled. Therefore, if you have an .htaccess file in a subdirectory and another one in a parent directory, the one in the subdirectory will be followed.

Showing error pages

Error handlers are setup so that custom pages can be displayed to users, should they encounter an error on your website hosting. For example, if they should encounter a ``Not found'' 404 error, they could get directed to a good looking page, rather than the boring default error page.

To achieve this, simply put this little snippet in your .htaccess file.
Quote:
ErrorDocument 400 /errors/404.html

ErrorDocument 403 /errors/403.html

ErrorDocument 404 /errors/404.html

ErrorDocument 500 /errors/500.html
You can name the pages anything you want, provided it is linked correctly in the .htaccess file.

The most common error pages are

Quote:
404 - Page not found error

400 - Bad Request

403 - Forbidden error

500 - Internal server error
Password protect

Password protecting a web directory can be achieved by putting this little snippet in your .htaccess file in the directory you want to protect.

Quote:
AuthType Basic

AuthName "Password Required"

AuthUserFile /www/passwords/.htpasswd
In order for the password protect to work, you should create a .htpasswd file. You can create it by doing these steps.

Quote:
[root@localhost ~]# cd /var/passwords

[root@localhost ~]# htpasswd -c .passwd username

New password:

Re-type new password:

Adding password for user username

[root@localhost ~]# cat .passwd

username:wLU7nnYVpdXO2

[root@localhost ~]#
In order for this to work, your Web administrator should have allowed ``AllowOverride AuthConfig'' in the server wide httpd.conf.

Denying users by IP or domain

You can deny users based on IP or IP block by putting in this snippet in your .htaccess.
Quote:
order allow,deny

deny from 98.654.321.12

deny from 98.654.322.

allow from all
The second line, specifically denies one IP 98.654.321.12. The third line denies all the IPs starting with 98.654.322. . This is particularly useful if you have seen strange activity on your website hosting by unknown IPs in your access logs.

Some webmasters use this feature to deny whole ISPs or datacenters access, especially if they find credit card fraud or increased attempts from poorly secured servers.

You can also deny by domain name. For example ``deny from .madguy.com'', denies all users from www.madguy.com or abc.madguy.com .


Changing the default page

Assume you are using index.php instead of index.html as your main home page. But the webserver is configured to access index.html first. All you need to do is to add this to your .htaccess.

Quote:
DirectoryIndex index.php index.html
This makes the php file the default file. In case the php file is not around, it will look for the index.html file.

Controlling PHP using htaccess

The good thing about htaccess is that I can use it to control the php variables as well. PHP's behaviour is controlled a large extent by the /etc/php.ini file. In a server shared by many website hostings, it may not be possible to change the php.ini file for everyone's special needs. Thats where the .htaccess file comes in.

For example, if you want to turn the register globals off, simply put this in the .htaccess file

Quote:
php_flag register_globals Off
In this way, you can override any php.ini variable, by putting such entries in the .htaccess file. Of course, this works only if it is allowed by the administrator.

Redirects

Webmasters use Redirects during maintenance(to redirect from index.html to tempmessage.html) or to redirect from an old file to a new file.

In order to redirect from http://yoursite.com/old/file.html to http://yoursite.com/new/file.html, simply put this line in your .htaccess file.

Quote:
Redirect /old/file.html http://yoursite.com/new/file.html
The /old is relative to the root of your website hosting. i.e at http://yoursite.com/old.

SSI

In order to allow SSI(Server Side Includes) in one directory, simply include this snippet in the .htaccess file in that directory.

Quote:
Options +Includes AddType text/html shtml AddHandler server-parsed shtml
__________________

Best Regards,
eUKScott
VPS Hosting || Managed Hosting
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 23:30.

 

Powered by vBulletin® Version 3.7.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by Web Hosting 3.1.0
Copyright © 2001-2008, eUKhost.com. All rights reserved.

 
Site Map

VPS Hosting
VPS Hosting plans

Dedicated Server Hosting
Dedicated Server plans

Business Web Hosting
100% uptime Hosting

Cpanel Hosting
cPanel Shared Hosting

Reseller Hosting
Reseller Web Hosting

Windows Hosting
Windows Shared Hosting

Windows VPS

Windows VPS Hosting

Semi Dedicated Servers
Semi-Dedicated Hosting

Dedicated Server Mirroring
Dedicated Server Mirroring

Webhosting Knowledgebase
Frequently asked Questions

Web Hosting Blog
eUKhost Blog

Web Hosting Support
Support Helpdesk

UK Data Center
eUKhost Datacenter

Web Hosting Forum
eUKhost Forum

Support Tutorials
Online Flash Tutorials

Offsite Back-up Plans
Remote Backup Service

Customer Testimonials
eUK Customer Testimonials


knowledgebase articles

eUKhost.com Services

Pre-Sales Questions
Pre-sales FAQ's

Domain Names
Domain registration FAQ's

cPanel Hosting
cPanel Hosting FAQ's

Windows Web Hosting
Plesk Control Panel

Reseller Hosting
Reseller Hosting FAQ's

VPS Hosting
Virtual Private Server

Semi-Dedicated Servers
Semi-Dedicated FAQ's

Dedicated Servers
Dedicated Server Hosting


popular blog categories


Web Hosting
Website Hosting articles

UK Web Hosting
UK Hosting articles

Dedicated Server Hosting
Dedicated Server guidelines

VPS Hosting
VPS hosting articles

cPanel Hosting
cPanel Hosting articles

Linux Operating System
Linux Operating techniques

Windows Web Hosting
Windows plesk articles