Upgrade to Pro — share decks privately, control downloads, hide ads and more …

WCTO:Dev 2012: Getting started with .htaccess for WordPress

275e113775bcd075ff1923687986b9a8?s=47 Shannon Smith
November 03, 2012

WCTO:Dev 2012: Getting started with .htaccess for WordPress

An introduction on how to configure your .htaccess file to do more than what WordPress provides by default. The talk will cover basics like setting up a preferred URL, and redirecting old page URLs for better SEO. How to optimize your site's files using gzip will also be covered, as well as preventing image hot linking, and more. A sample .htaccess file will be provided to all attendees. A useful introduction to a very important file for any shared hosting environment.

275e113775bcd075ff1923687986b9a8?s=128

Shannon Smith

November 03, 2012
Tweet

Transcript

  1. November 3, 2012 Getting started with .htaccess for WordPress WordCamp

    Toronto: Developers 2012
  2. Shannon Smith Web Developer at Café Noir Design www.cafenoirdesign.com @cafenoirdesign

  3. What We’ll Cover ✤ Introduction ✤ Getting Started ✤ .htaccess

    for SEO ✤ .htaccess for Security ✤ .htaccess for Optimization ✤ Resources ✤ Closing
  4. Introduction

  5. What Is an .htaccess File? .htaccess files (or “distributed configuration

    files”) provide a way to make configuration changes on a per-directory basis Official Apache Documentation
  6. In English, Please? .htaccess is a configuration file for use

    on web servers running the Apache Web Server software
  7. Why Do We Care? Photo: Linus Bohman

  8. What Does It Look Like?

  9. Where Is It?

  10. When Can We Use .htaccess ? ✤ Apache Web Server

    software ✤ Linux/Unix server ✤ Shared Hosting
  11. But...Measure Twice, Cut Once Photo:Kari

  12. Getting Started

  13. Basic Syntax

  14. Commenting

  15. Enable Basic Rewriting

  16. Allow URL Rewriting

  17. Rewrite Base

  18. Match a Regex String

  19. Use Conditionals

  20. Rewrite URLs

  21. A Basic mod_rewrite Command RewriteRule Pattern Substitution [Flag(s)]

  22. That’s It!

  23. Troubleshooting

  24. Why Isn’t It Working? “I don’t see anything." Your Text

    Editor Photo:Emilio Labrador
  25. Why Isn’t It Working? “Are you sure you spelled that

    correctly?" Your English Teacher
  26. Why Isn’t It Working? “You can’t do that." Apache Photo:Achim

    Hepp
  27. Why Isn’t It Working? “Welcome." The Infinite Loop Photo:smittenkittenorig

  28. Why Isn’t It Working? “We don’t allow that for security

    reasons". Your Hosting Provider Photo:Sam Howzit
  29. .htaccess for SEO

  30. Basic Rules of SEO ✤ Don’t repeat yourself ✤ Don’t

    repeat yourself ✤ Don’t repeat yourself Photo: jerebu
  31. Redirect a Single Page

  32. To www or Not to www

  33. Redirect Additional Domain Names

  34. .htaccess for Security

  35. Hide Your Files

  36. Hide Your Server Information

  37. Block Bad Referring Sites

  38. Block Site Rippers

  39. .htaccess for Optimization

  40. Prevent Image Hotlinking

  41. File Compression

  42. Set Caching Limits

  43. Use Asset Versioning <link rel="stylesheet" href="css/style.css?v=2">

  44. Turn Off ETags

  45. Resources

  46. Resources ✤ Official Apache Documentation http://httpd.apache.org/docs/2.4/howto/htaccess.html ✤ .htaccess made easy

    by Jeff Starr http://htaccessbook.com ✤ Protect your WordPress site with .htaccess (.net magazine) http://www.netmagazine.com/tutorials/protect-your-wordpress-site-htaccess ✤ Comprehensive guide to .htaccess http://www.javascriptkit.com/howto/htaccess.shtml ✤ The Ultimate Guide to .htaccess Files (Nettuts) http://net.tutsplus.com/tutorials/other/the-ultimate-guide-to-htaccess-files/ ✤ Practical Mod_Rewrite for Web Developers http://www.snipe.net/2009/02/practical-mod_rewrite/ ✤ mod_rewrite Cheat Sheet http://www.addedbytes.com/cheat-sheets/mod_rewrite-cheat-sheet/ ✤ Stupid htaccess Tricks http://perishablepress.com/stupid-htaccess-tricks/
  47. Closing

  48. Shannon Smith Web Developer at Café Noir Design https://speakerdeck.com/u/cafenoirdesign www.cafenoirdesign.com

    @cafenoirdesign