Slide 1

Slide 1 text

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

Slide 2

Slide 2 text

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

Slide 3

Slide 3 text

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

Slide 4

Slide 4 text

Introduction

Slide 5

Slide 5 text

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

Slide 6

Slide 6 text

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

Slide 7

Slide 7 text

Why Do We Care? Photo: Linus Bohman

Slide 8

Slide 8 text

What Does It Look Like?

Slide 9

Slide 9 text

Where Is It?

Slide 10

Slide 10 text

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

Slide 11

Slide 11 text

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

Slide 12

Slide 12 text

Getting Started

Slide 13

Slide 13 text

Basic Syntax

Slide 14

Slide 14 text

Commenting

Slide 15

Slide 15 text

Enable Basic Rewriting

Slide 16

Slide 16 text

Allow URL Rewriting

Slide 17

Slide 17 text

Rewrite Base

Slide 18

Slide 18 text

Match a Regex String

Slide 19

Slide 19 text

Use Conditionals

Slide 20

Slide 20 text

Rewrite URLs

Slide 21

Slide 21 text

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

Slide 22

Slide 22 text

That’s It!

Slide 23

Slide 23 text

Troubleshooting

Slide 24

Slide 24 text

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

Slide 25

Slide 25 text

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

Slide 26

Slide 26 text

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

Slide 27

Slide 27 text

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

Slide 28

Slide 28 text

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

Slide 29

Slide 29 text

.htaccess for SEO

Slide 30

Slide 30 text

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

Slide 31

Slide 31 text

Redirect a Single Page

Slide 32

Slide 32 text

To www or Not to www

Slide 33

Slide 33 text

Redirect Additional Domain Names

Slide 34

Slide 34 text

.htaccess for Security

Slide 35

Slide 35 text

Hide Your Files

Slide 36

Slide 36 text

Hide Your Server Information

Slide 37

Slide 37 text

Block Bad Referring Sites

Slide 38

Slide 38 text

Block Site Rippers

Slide 39

Slide 39 text

.htaccess for Optimization

Slide 40

Slide 40 text

Prevent Image Hotlinking

Slide 41

Slide 41 text

File Compression

Slide 42

Slide 42 text

Set Caching Limits

Slide 43

Slide 43 text

Use Asset Versioning

Slide 44

Slide 44 text

Turn Off ETags

Slide 45

Slide 45 text

Resources

Slide 46

Slide 46 text

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/

Slide 47

Slide 47 text

Closing

Slide 48

Slide 48 text

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