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

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

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.

Shannon Smith

November 03, 2012
Tweet

More Decks by Shannon Smith

Other Decks in Technology

Transcript

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

    View Slide

  2. Shannon Smith
    Web Developer at Café Noir Design
    www.cafenoirdesign.com
    @cafenoirdesign

    View Slide

  3. What We’ll Cover
    ✤ Introduction
    ✤ Getting Started
    ✤ .htaccess for SEO
    ✤ .htaccess for Security
    ✤ .htaccess for Optimization
    ✤ Resources
    ✤ Closing

    View Slide

  4. Introduction

    View Slide

  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

    View Slide

  6. In English, Please?
    .htaccess is a configuration file for
    use on web servers running the
    Apache Web Server software

    View Slide

  7. Why Do We
    Care?
    Photo: Linus Bohman

    View Slide

  8. What Does It Look Like?

    View Slide

  9. Where Is It?

    View Slide

  10. When Can We Use .htaccess ?
    ✤ Apache Web Server software
    ✤ Linux/Unix server
    ✤ Shared Hosting

    View Slide

  11. But...Measure Twice, Cut Once
    Photo:Kari

    View Slide

  12. Getting Started

    View Slide

  13. Basic Syntax

    View Slide

  14. Commenting

    View Slide

  15. Enable Basic Rewriting

    View Slide

  16. Allow URL Rewriting

    View Slide

  17. Rewrite Base

    View Slide

  18. Match a Regex String

    View Slide

  19. Use Conditionals

    View Slide

  20. Rewrite URLs

    View Slide

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

    View Slide

  22. That’s It!

    View Slide

  23. Troubleshooting

    View Slide

  24. Why Isn’t It
    Working?
    “I don’t see
    anything."
    Your Text Editor
    Photo:Emilio Labrador

    View Slide

  25. Why Isn’t It
    Working?
    “Are you sure you
    spelled that
    correctly?"
    Your English Teacher

    View Slide

  26. Why Isn’t It
    Working?
    “You can’t do
    that."
    Apache
    Photo:Achim Hepp

    View Slide

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

    View Slide

  28. Why Isn’t It
    Working?
    “We don’t allow
    that for security
    reasons".
    Your Hosting Provider
    Photo:Sam Howzit

    View Slide

  29. .htaccess for SEO

    View Slide

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

    View Slide

  31. Redirect a Single Page

    View Slide

  32. To www or Not to www

    View Slide

  33. Redirect Additional Domain Names

    View Slide

  34. .htaccess for Security

    View Slide

  35. Hide Your Files

    View Slide

  36. Hide Your Server Information

    View Slide

  37. Block Bad Referring Sites

    View Slide

  38. Block Site Rippers

    View Slide

  39. .htaccess for Optimization

    View Slide

  40. Prevent Image Hotlinking

    View Slide

  41. File Compression

    View Slide

  42. Set Caching Limits

    View Slide

  43. Use Asset Versioning

    View Slide

  44. Turn Off ETags

    View Slide

  45. Resources

    View Slide

  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/

    View Slide

  47. Closing

    View Slide

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

    View Slide