Web Developers sometimes use file.ext?v=004 as a version control system to force visitors to use updated files. This is terrible. Instead link to apache-003.css and set it to be cached forever. When you change the file you just change the links to apache-004.css. That eliminates millions of bandwidth and resource robbing If-Modified-Since requests. You only need Apache with mod_rewrite, and 1-10 minutes!
Tagged: Cache, Cache-Control, caching, htaccess, If-Modified-Since, mod_rewrite | 2 Comments | Continue...
This is not an introduction to .htaccess… This is the evolution of .htaccess… The BEST, the ORIGINAL, the NEWEST, and the most HIGHEST, FLYEST .htaccess tricks I can find.
Originally known as the “Ultimate .htaccess Guide”, its changed over the years by adding new .htaccess tricks and .htaccess examples to it.. I also add my favorite .htaccess links, the best .htaccess articles on AskApache, the coolest .htaccess experiments, the Web’s best .htaccess hacks, and update this article on the regular.
Tagged: .htaccess examples, Apache, Cache, caching, Files, FilesMatch, Google, Hacking, howto, htaccess, htaccess guide, htaccess help, htaccess howto, htaccess rewrite, htaccess tricks, htaccess tutorial, httpd, litespeed, mod_rewrite, Mod_Security, rewritecond, rewriterule, sample .htaccess, Security, SEO, seo secrets, SetEnvIf, ssl, ultimate htaccess | 56 Comments | Continue...
SetEnv, SetEnvIf, and SetEnvIfNoCase directives conditionally set environment variables accessible by scripts and apache based on HTTP Headers, Variables, and Request information.
Tagged: Examples, htaccess, mod_rewrite, mod_setenvif, SetEnv, SetEnvIf | 4 Comments | Continue...
There are a total of 57 HTTP Status Codes recognized by the Apache Web Server. Wouldn’t you like to see what all those headers and their output, ErrorDocuments look like?
Tagged: Apache, errordocument, htaccess, HTTP Error, HTTP Status Codes, PHP, Redirect, Status Code | 19 Comments | Continue...
HTTP Headers
HTTP Header Name
Header Description
Example HTTP Header
Accept
Content-Types that are acceptable
Accept: text/xml,application/xml,application/xhtml+xml,text/html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Charset
Character sets that are acceptable
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Accept-Encoding
Acceptable encodings
Accept-Encoding: gzip,deflate
Accept-Language
Acceptable languages for response
Accept-Language: en-us,en
Accept-Ranges
What partial content range types this server supports
Accept-Ranges: bytes
Age
The age the object has been in a proxy cache in seconds
Age: 7200
Allow
Valid actions for a specified resource. To be used for a 405 Method not allowed
Allow: GET,HEAD,POST,OPTIONS,TRACE
Authorization
Authentication credentials for HTTP authentication
Authorization: Basic UXNrYXBhggRfoopc5NteWFzcw==
Cache-Control
Controls how proxies may cache this object
Cache-Control: max-age=7200, public
Connection
What type of connection the user-agent would prefer
Connection: Keep-Alive
Content-Encoding
The type of encoding used on the data
Content-Encoding: gzip
Content-Language
The language the content is in
Content-Language: en-us
Content-Length
The length of the content in bytes
Content-Length: 5356
Content-Location
An alternate location for the returned data
Content-Location: /index.html
Content-MD5
An MD5 sum of the content of the response
Content-MD5: 1167b9c13ad2b6d3694493fc47976c8
Content-Range
Where in a full body message this partial message belongs
Content-Range: bytes 110-2034/2035
Content-Type
The mime type of this content
Content-Type: text/html; charset=UTF-8
Date
The date and time that the message was sent
Date: Sat, 05 Jan 2008 09:27:35 GMT
Host
The domain name of the server (for virtual hosting)
Host: www.askapache.com
If-Modified-Since
Allows a 304 Not Modified to be returned
If-Modified-Since: Sat, 05 Jan 2007 09:26:12 GMT
Last-Modified
The last modified date for the requested object
Last-Modified: Sat, 05 Jan 2008 09:26:12 GMT
Location
Used in redirection
Location: http://www.askapache.com/
Server
A name for the server
Server: Apache/2.0.61 (Unix) PHP/4.4.7 mod_ssl/2.0.61 OpenSSL/0.9.7e mod_fastcgi/2.4.2 DAV/2 SVN/1.4.2
User-Agent
The user agent string of the user agent
User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.7) Gecko/20070914 Firefox/2.0.0.7
List of HTTP Response Status Codes
1xx Info / Informational
HTTP_INFO – Request received, continuing process.
Indicates a provisional response, consisting only of the Status-Line and optional headers, and is terminated by an empty line.
100 Continue – HTTP_CONTINUE
101 Switching Protocols – HTTP_SWITCHING_PROTOCOLS
102 Processing – HTTP_PROCESSING
2xx Success / OK
HTTP_SUCCESS – The action was successfully received, understood, and accepted.
Indicates that the client’s request was successfully received, understood, and accepted.
200 OK – HTTP_OK
201 Created – HTTP_CREATED
202 Accepted – HTTP_ACCEPTED
203 Non-Authoritative Information – HTTP_NON_AUTHORITATIVE
204 No Content – HTTP_NO_CONTENT
205 Reset Content – HTTP_RESET_CONTENT
206 Partial…
Update: This article is a bit dated, to get the newest and latest Google Analytics Speed Tips, check out the 3 part update about Hosting, Cookie Domains, and JavaScript Loading and Failproofs
Ever notice that sometimes your sites take a while to load all the way because google’s urchin.js file is taking forever? You may recognize this problem when you see something similar to this in your browsers status bar “Transferring data from google-analytics.com…”
Time To Setup?
4 minutes I got tired of seeing that all the time and so I set up an automated cronjob that runs every 12 hours and downloads the latest version from google, and saves it to my website directory, then I reference /urchin.js instead of http://www.google-analytics.com/urchin.js.. and my site loads a lot faster!
Take a look at the source for this page if you want to see what is going on (look at the bottom)
There are 2 pretty major things that you accomplish by hosting urchin.js locally
You Enable persistant connections
You ensure that the correct 304 Not Modified header is sent back to your site visitors instead of reserving the entire file.
The urch.sh shell script
Create a shell script called urch.sh.. this will be executed every 1/day or 1/wk, whatever you want. The following script removes the local urchin.js, then it wgets the latests version into the local directory.
#!/bin/sh
rm /home/user/websites/askapache.com/z/j/urchin.js
cd /home/user/websites/askapache.com/z/j/
wget http://www.google-analytics.com/urchin.js
chmod 644 /home/user/websites/askapache.com/z/j/urchin.js
cd ${OLDPWD}
exit 0;
Improved shell script
I realized right away that a more modular shell script would be needed.. I admin like 50+ web-sites and it would be stupid to have to type the same block of code 50 times, wget the same file 50 times, etc.. So this version downloads the urchin.js file into a temporary directory, then it copies it OVER the old file for each directory. So 1 GET request…
Tagged: Google Analytics, urchin.js | 11 Comments | Continue...
If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified Responses.
Tagged: Cache, etag, Headers, htaccess, http, Last-Modified | 6 Comments | Continue...
By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.
Tagged: Cache, Cache Validation, Etags, optimization, YSlow | 8 Comments | Continue...
This explains the basic methods to get started caching with php headers
If you examine the preferences dialog of any modern Web browser (like Internet Explorer, Safari or Mozilla), you’ll probably notice a ‘cache’ setting. This lets you set aside a section of your computer’s hard disk to store representations that you’ve seen, just for you. The browser cache works according to fairly simple rules. It will check to make sure that the representations are fresh, usually once a session (that is, the once in the current invocation of the browser).
2 awesome ways to implement caching on your website using Apache .htaccess or httpd.conf. Both methods are extremely simple to set up and will dramatically speed up your site!
The love of liberty is the love of others; the love of power is the love of ourselves.
-- William Hazlitt
Please consider donating to support active development of the free software and articles here.![]()
The power of the Web is in its universality. Access by everyone regardless of disability is an essential aspect. Tim Berners-Lee
It's very simple - you read the protocol and write the code. -Bill Joy
HTML | DCMI | GRDDL | XOXO | XDMP | XFN | DOM | XML | XHTML 1.1 Strict | CSS 2.1 | W3C | TLDP | WAI | DISA | ICSI | GIAC | SANS RR | GHOST | DEFCON | NIST | DHS CYBER | NIST | Phrack | GDB | IEEE | GIT
↑ TOPExcept where otherwise noted, content on this site is licensed under a Creative Commons Attribution 3.0 License, just credit with a link.
This site is not supported or endorsed by The Apache Software Foundation (ASF). All software and documentation produced by The ASF is licensed. "Apache" is a trademark of The ASF. HTTPD based on NCSA HTTPd