Configuring .htaccess on Your Apache Server

For server administrators who need a way to make minor configuration updates without editing the http.conf configuration file, .htaccess facilitates updates to Apache modules including memory limits, access limitations, password protection and other configuration features.

Importantly, the file is a basic ASCII file which should remain unformatted and edited in a simple text editor in order to prevent misalignment in the format structure. In the file .htaccess is the extension, so make sure you don’t update the name of the file, which can prevent your Apache server from recognizing it properly. At the same time, when you upload the file make sure you update your CHMOD settings to 644 and upload only in ASCII mode (binary uploads can skew the formatting.)

When updating your .htaccess file makes sure the entire line along the text is visible, since a complete line is used to update a setting. There are a variety of settings you can update via .htaccess, and this guide covers some of the most prominent updates:

Limiting Access to Users by Referrer

Most of the time, web traffic is beneficial to your site, but you may want to block certain referrers which are causing problems. In these cases you can implement a simple block for referral sources:

RewriteEngine on
# Options +FollowSymlinks
RewriteCond %{HTTP_REFERER} blockedsite\.com [NC]
RewriteRule .* – [F]

Adding MIME extensions

If your Apache server isn’t delivering file types with the proper extensions, you can update your .htaccess file to ensure proper delivery. A common incidence of this is in media files such as audio or video tracks, which aren’t often delivered with the right application. An update to the file ensures you can stream audio properly within a browser without the user being prompted to download or select the right application. For example, a common update is to set Flash settings:

AddType application/x-shockwave-flash swf

Prevent Hot Linking of Media Files

Often times you’ll want to reduce indirect bandwidth caused by other sites embedding your images, videos or sound files. In these cases you can implement a few lines on your .htaccess file to deliver an alternative image instead:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?yoursite.com/.*$ [NC]
RewriteRule \.(gif|jpg)$ http://www.yoursite.com/nothotlink.gif [R,L]

0 responses so far ↓

There are no comments yet...Kick things off by filling out the form below.

Leave a Comment




 

Search Website

 
 
 

Top 10 Hosting Companies

MyHosting - $4.00 USD
InMotion Hosting - $5.95 USD
WebHostingHub - $4.95 USD
JustHost - $3.95 CDN
iPage - $3.50 CDN
HostGator - $4.95 USD
FatCow - $3.67 USD
GreenGeeks - $4.95 USD
BlueHost - $6.95 USD
10 GoDaddy - $4.11 CDN