Help - Search - Members - Calendar
Full Version: Ultimate htaccess Article
HTMLHelp Forums > Programming > Web Server Configuration
John Pozadzides
I was reviewing this article and had some questions for the Apache experts. Since Liam, Daren and the other members of the WDG know all this crap I don't have to. :-)

I was considering making some of these changes to my htaccess file for my Wordpress installation and figured I ought to run it by you guys first...

According to the article, you can "Dramatically Speed up your site by implementing Caching!" The author provides the following code but doesn't explain what it means in english:
CODE
# MONTH
<FilesMatch "\.(flv|gif|jpg|jpeg|png|ico|swf)$">
Header set Cache-Control "max-age=2592000"
</FilesMatch>

# WEEK
<FilesMatch "\.(js|css|pdf|txt)$">
Header set Cache-Control "max-age=604800"
</FilesMatch>

# DAY
<FilesMatch "\.(html|htm)$">
Header set Cache-Control "max-age=43200"
</FilesMatch>
Prevent Files image/file hotlinking and bandwidth stealing
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ http://www.askapache.com/legal.gif [R=302,L]
  • Am I to understand that this basically caches image files for a month, JS/CSS for a week and html for a day?
  • If so how does this affect the fact that Wordpress is entirely PHP driven? In other words, if I make changes to my PHP (which I do all the time) would it prevent me from seeing the changes immediately?
  • My site has more MB of images than RAM so what happens if the server runs out of RAM (it's Linux)?
  • What would happen if I were to theoretically change my CSS or something that was cached. Would the system know that and re-cache it or would you have to manually clear the cache somehow?

They also say you can "Prevent Files image/file hotlinking and bandwidth stealing" with the following:
CODE
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://(www\.)?askapache.com/.*$ [NC]
RewriteRule \.(gif|jpg|swf|flv|png)$ http://www.askapache.com/legal.gif [R=302,L]

Is there any reason NOT do do this?

Finally, what's the ServerSignature and why would you want to turn it off?

Thanks,

John
pandy
I thought ServerSignature was that bit a server identifies itself with in the headers but oviously not.
http://httpd.apache.org/docs/1.3/mod/core....serversignature

The guys behind http://www.askapache.com/ haven't read http://www.w3.org/Provider/Style/URI.html . Every darn hit in Google ends up at their error page. ninja.gif
Tom H.
Good explanations of caching are found, among other places, at http://www.mnot.net/cache_docs/. Too bad the article you read doesn't provide any background.

The techniques they give don't cause your server to cache, all they do is send additional information to proxy servers which may sit between your web server and the end clients. (Some ISPs and many companies use proxy servers to reduce bandwidth use and speed up content delivery to their users.)

Proxy servers are smart enough to not cache server-generated pages (such as your php pages). All the disk files (CSS, images, HTML) served from your site are candidates for caching. Those .htaccess directives send additional information to proxy servers to help them decide whether to cache and for how long. For files which are rarely modified, it's beneficial for everyone if they are cached for a long time, and you can encourage that behavior by sending explicit information rather then making them guess.

I encourage caching of larger static files (images and PDFs), and discourage caching of frequently modified static files (HTML pages with timely information.)

Unless you have a problem with "bandwidth stealing" I would disregard their hint for that, since every URL rewrite rule gives your server more work to perform.

And the server signature setting is really just a cosmetic matter of choice.
Peter1968
I'd suggest outputting a 403 rather than redirect to an image for bandwidth leeching. It tells search engines the right things as well as the dude using your images/URL on his/her site.

As for Tom H's advice re: giving the server more work, I'd argue that's what the server is there for, isn't it? I'd rather save 3-4Gb in bandwidth a month rather than hurt Apache's feelings by giving it an extra 2-3% overhead. Make it earn its keep.

Secondly, mod_rewrite is a pretty cleanly written beast and what ever the extra work there is will be minimal, especially if your site is the only thing that lives on the box.

CODE

Prevent Files image/file hotlinking and bandwidth stealing


That's needs to be commented out obviously.
John Pozadzides
Thanks for all the great explanations guys. They help me better understand what's going on there.

I'm still uncertain if I should even worry about doing these at all. It sounds like none of it will make much of a difference since my personal site is on my own personal dedicated server that is WAY underutilized.

John
askapache
Man you were so close!

I wrote an entire separate article on that code that you posted above.. you can read in its entirety on askApache.com If that article doesn't answer your questions let me know!
askapache
BTW John the link to the article is now http://www.askapache.com/2006/htaccess/apache-htaccess.html
Darin McGrew
See also Cool URIs don't change
askapache
Nice article Darin, I guess my url isn't cool smile.gif
http://www.askapache.com/htaccess/apache-htaccess.html
Darin McGrew
And your CSS seems rather bizarre. Do you expect line-height:.75em to improve the readability of your lists of links?
askapache
Yeah my CSS is due for a complete overhaul.
askapache
Yo Darin McGrew,

I just finished upgrading the CSS for my website, which you can check out at http://www.askapache.com/


Main style sheet, at http://z.askapache.com/z/c/apache-12.css

Print style sheet, at http://z.askapache.com/z/c/apacheprint-12.css

Let me know if I should change anything else!
Darin McGrew
QUOTE
Let me know if I should change anything else!
Looking at the main style sheet, the thing that jumps out is the use of px for font sizes. Use a font size of 100% for body text, use larger percentages for headings and the like, and use (slightly) smaller percentages for legalese and similar fine print.

Also, the W3C CSS Validator reports some CSS errors.
askapache
Thanks Darin, its always nice to get some feedback! I just finished combining my main css file with my print css file, and verified the new single css file is CSS 2.1 warning free!
pandy
There is a CSS forum where you can post questions about your CSS.
http://forums.htmlhelp.com/index.php?showforum=11
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2010 Invision Power Services, Inc.