Author Archives: administrator

htaccess useful tips

1. Custom Directory Index Files

DirectoryIndex index.html index.php index.htm

2. Custom Error Pages

#BAD_REQUEST
ErrorDocument 400 http://www.yourdomain.com/index.html
#UNAUTHORIZED
ErrorDocument 401 http://www.yourdomain.com/index.html
#FORBIDDEN
ErrorDocument 403 http://www.yourdomain.com/index.html
#NOT_FOUND
ErrorDocument 404 http://www.yourdomain.com/index.html
#METHOD_NOT_ALLOWED
ErrorDocument 405 http://www.yourdomain.com/index.html
#REQUEST_TIME_OUT
ErrorDocument 408 http://www.yourdomain.com/index.html
#GONE
ErrorDocument 410 http://www.yourdomain.com/index.html
#LENGTH_REQUIRED
ErrorDocument 411 http://www.yourdomain.com/index.html
#PRECONDITION_FAILED
ErrorDocument 412 http://www.yourdomain.com/index.html
#REQUEST_ENTITY_TOO_LARGE
ErrorDocument 413 http://www.yourdomain.com/index.html
#REQUEST_URI_TOO_LARGE
ErrorDocument 414 http://www.yourdomain.com/index.html
#UNSUPPORTED_MEDIA_TYPE
ErrorDocument 415 http://www.yourdomain.com/index.html
#INTERNAL_SERVER_ERROR
ErrorDocument 500 http://www.yourdomain.com/index.html
#NOT_IMPLEMENTED
ErrorDocument 501 http://www.yourdomain.com/index.html
#BAD_GATEWAY
ErrorDocument 502 http://www.yourdomain.com/index.html
#SERVICE_UNAVAILABLE
ErrorDocument 503 http://www.yourdomain.com/index.html
#VARIANT_ALSO_VARIES
ErrorDocument 506 http://www.yourdomain.com/index.html

3. Control access at files & directory level

<Files .htaccess>
order allow,deny
deny from all
</Files>
<FilesMatch "(\.log|dbclass\.php|\..*)">
Order allow,deny
Deny from all
Satisfy All
</FilesMatch>

4. Modifying the Environment Variable

Environment variables contain information used by server-side includes and CGI. Set / Unset environment variables using SetEnv and UnSetEnv.
SetEnv SITE_WEBMASTER "Jack Sprat"
SetEnv SITE_WEBMASTER_URI mailto:Jack.Sprat@characterology.com
UnSetEnv REMOTE_ADDR

5. 301 Redirect using htaccess

If you want to redirect from an…Read More

Tags: General
Posted in General | Leave a comment

.htaccess for old browser

Below are some good examples of how to handle older browsers when using gzip and expiration dates on your files. Older browsers sometimes have difficulties with gzip so you may want to use this code as well.

# Enable ETag
FileETag MTime Size
# Set expiration header
ExpiresActive on
ExpiresDefault “access plus 1 year”
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/css A2592000
# Compress some text file types
AddOutputFilterByType DEFLATE text/html text/plain text/css text/xml application/x-javascript text/javascript application/javascript
# Deactivate compression for buggy browsers
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0 no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

Tags: Site Speed & Performance, htaccess tips
Posted in Site Speed & Performance | Tagged | 1 Comment