.htaccess for Webmasters
I tried to keep these htaccess code snippets extremely minimalistic. The focus here is not to explain Apache htaccess or httpd.conf, this is a list of best-practice Apache,htaccess code snippets.
When site is “Under Construction�
This lets google crawl, lets me access (1.1.1.1) without a password, and lets access from anyone WITH a password. It also allows for XHTML and CSS validation through w3.org
update combined allow code credit: megaspaz
AuthName "Under Development" AuthUserFile /home/askapache.com/.htpasswd AuthType basic Require valid-user Order Deny,Allow Deny from all Allow from 1.1.1.1 w3.org googlebot.com google.com google-analytics.com Satisfy Any
Redirect everyone to different site except 1 IP
ErrorDocument 403 http://www.htaccesselite.com Order deny,allow Deny from all Allow from 1.1.1.1
Redirect all but 1 IP to different site, using mod_rewrite
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.1.1.1
RewriteRule .* http://www.htaccesselite.com [R=302,L]
Redirect Everyone but you to alternate page on your server
RewriteEngine On
RewriteBase /
RewriteCond %{REMOTE_HOST} !^1.1.1.1
RewriteCond %{REQUEST_URI} !/temporary-offline.html$
RewriteRule .* /temporary-offline.html [R=302,L]
Set the Timezone of the server
SetEnv TZ America/Indianapolis
Set the Server Administrator Email
Include a link to your email address in Apache-Generated Error Documents. Shows up on default Apache error pages
ServerSignature EMail SetEnv SERVER_ADMIN spamkill@spamkill.com
Turn off the ServerSignature
Turns off the address part of your Server Signature in Apache generated Error Documents.
ServerSignature Off
Force File download, do not display/open in browser
In your HTML directly link to the file.. <a href="/movies/mov1.avi">Download Movie1</a>. Now you will get a pop-up box asking whether you want to save the file or open it.
AddType application/octet-stream .avi AddType application/octet-stream .mpg AddType application/octet-stream .mov AddType application/octet-stream .pdf
Process .gif files with a cgi script
When a user requests a .gif file (image/gif) the server instead of serving that .gif file it serves the results of /cgi-bin/filter.cgi
Action image/gif /cgi-bin/filter.cgi
Process Requests with certain Request Methods
Script PUT /cgi-bin/upload.cgi Script HEAD /cgi-bin/head-robot.cgi
Make any file be a certain filetype
Makes image.gif, blah.html, index.cgi all act as php
ForceType application/x-httpd-php
Use IfModule for robustness
Basically if the module is found it will perform the code inside the tag.
<IfModule mod_rewrite.c> # any mod_rewrite directives here </IfModule> <IfModule mod_expires.c> # any Expires Directives go here </IfModule> <IfModule mod_headers.c> # any Header directives go here </IfModule>

- Running PHP Scripts with Cron
- Create Excel files with PHP
- Cache in PHP
- Configuring Apache for Maximum Performance
- Basic working with files in PHP
- How to Develop Web Applications with Ajax
- Display content dynamically with AJAX
- Creating thumbnail - Resize an image with PHP
- Rating and labelling your ASP.NET website
- AJAX Generic Form Parser - With Validation
- Old broken mill
- In The Sky Photo Effect
- Concept car design
- Smooth glass type
- Create a Glowing Abstract Light Vector Graphic
- Form a Threatening Troop of Archers
- Easiest way to implement Ajax in your ASP.Net 2.0 applications
- Going to the Polls with PHP: Part 1 - The frontside
- Illustrator Tutiorials Screenshot Tropical Transparency Effect
- Create a Citrus Fruit Design From Scratch in Photoshop
Login
Friends' Sites
Contact Us
Categories
- 3D
- ASP
- C#
- CSS
- Database
- Flash
- GIMP
- Hosting
- Illustrator
- Java
- Javascript
- Linux
- Photoshop
- PHP
- Web Design
- Windows

2,428 views
No comments
(4 votes, average: 4.25 out of 5)
No comments
Jump to comment form | comments rss [?] | trackback uri [?]