Getting Started with .htaccess for WordPress

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. Presented at WordCamp Montreal 2014.

275e113775bcd075ff1923687986b9a8?s=128

Shannon Smith

August 17, 2014
Tweet

Transcript

  1. Getting Started with .htaccess for Wordpress Shannon Smith All rights

    reserved © Café Noir Design Inc., 2014.
  2. Shannon Smith Web Developer Café Noir Design ! ! www.cafenoirdesign.com

    @cafenoirdesign All rights reserved © Café Noir Design Inc., 2014.
  3. What We’ll Cover • Introduction • Getting Started • .htaccess

    for SEO • .htaccess for Security • .htaccess for Optimization • Resources • Closing All rights reserved © Café Noir Design Inc., 2014.
  4. Introduction All rights reserved © Café Noir Design Inc., 2014.

  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 All rights reserved © Café Noir Design Inc., 2014.
  6. In English, Please? .htaccess is a configuration file for use

    on web servers running the Apache Web Server software All rights reserved © Café Noir Design Inc., 2014.
  7. A Little History… .htaccess = hypertext access All rights reserved

    © Café Noir Design Inc., 2014.
  8. Why Do We Care? Photo: Linus Bohman All rights reserved

    © Café Noir Design Inc., 2014.
  9. What Does It Look Like? All rights reserved © Café

    Noir Design Inc., 2014.
  10. Where Is It? All rights reserved © Café Noir Design

    Inc., 2014.
  11. When Can We Use .htaccess ? • Apache Web Server

    software • Linux/Unix server • Shared Hosting All rights reserved © Café Noir Design Inc., 2014.
  12. But...Measure Twice, Cut Once Photo:Kari All rights reserved © Café

    Noir Design Inc., 2014.
  13. Getting Started All rights reserved © Café Noir Design Inc.,

    2014.
  14. Basic Syntax All rights reserved © Café Noir Design Inc.,

    2014.
  15. Commenting All rights reserved © Café Noir Design Inc., 2014.

  16. Enable Basic Rewriting All rights reserved © Café Noir Design

    Inc., 2014.
  17. Allow URL Rewriting All rights reserved © Café Noir Design

    Inc., 2014.
  18. Rewrite Base All rights reserved © Café Noir Design Inc.,

    2014.
  19. Match a Regular Expression (Regex) String All rights reserved ©

    Café Noir Design Inc., 2014.
  20. Use “IfModule” directives All rights reserved © Café Noir Design

    Inc., 2014.
  21. Rewrite URLs All rights reserved © Café Noir Design Inc.,

    2014.
  22. A Basic mod_rewrite Command RewriteRule Pattern Substitution [Flag(s)] All rights

    reserved © Café Noir Design Inc., 2014.
  23. That’s It! All rights reserved © Café Noir Design Inc.,

    2014.
  24. Troubleshooting All rights reserved © Café Noir Design Inc., 2014.

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

    Editor Photo:Emilio Labrador All rights reserved © Café Noir Design Inc., 2014.
  26. Why Isn’t It Working? “Are you sure you spelled that

    correctly?" Your English Teacher All rights reserved © Café Noir Design Inc., 2014.
  27. Why Isn’t It Working? “You can’t do that." Apache Photo:Achim

    Hepp All rights reserved © Café Noir Design Inc., 2014.
  28. Why Isn’t It Working? “Welcome." The Infinite Loop Photo:smittenkittenorig All

    rights reserved © Café Noir Design Inc., 2014.
  29. Why Isn’t It Working? “We don’t allow that for security

    reasons". Your Hosting Provider Photo:Sam Howzit All rights reserved © Café Noir Design Inc., 2014.
  30. .htaccess for SEO All rights reserved © Café Noir Design

    Inc., 2014.
  31. Basic Rules of SEO • Don’t repeat yourself • Don’t

    repeat yourself • Don’t repeat yourself Photo: jerebu All rights reserved © Café Noir Design Inc., 2014.
  32. Redirect a Single Page All rights reserved © Café Noir

    Design Inc., 2014.
  33. To www or Not to www All rights reserved ©

    Café Noir Design Inc., 2014.
  34. Redirect Additional Domain Names All rights reserved © Café Noir

    Design Inc., 2014.
  35. .htaccess for Security All rights reserved © Café Noir Design

    Inc., 2014.
  36. Hide Your Files All rights reserved © Café Noir Design

    Inc., 2014.
  37. Hide Your Server Information All rights reserved © Café Noir

    Design Inc., 2014.
  38. Block Bad Referring Sites All rights reserved © Café Noir

    Design Inc., 2014.
  39. Block Site Rippers All rights reserved © Café Noir Design

    Inc., 2014.
  40. .htaccess for Optimization All rights reserved © Café Noir Design

    Inc., 2014.
  41. Prevent Image Hotlinking All rights reserved © Café Noir Design

    Inc., 2014.
  42. File Compression All rights reserved © Café Noir Design Inc.,

    2014.
  43. Set Caching Limits All rights reserved © Café Noir Design

    Inc., 2014.
  44. Use Asset Versioning <link rel="stylesheet" href="css/style.css?v=2"> All rights reserved ©

    Café Noir Design Inc., 2014.
  45. Asset Versioning with wp_enqueue_style <?php wp_enqueue_style( $handle, $src, $deps, $ver,

    $media ); ?> ! <?php wp_enqueue_style( 'example-style', stylesheet.css(), false, '1.0.0', all ); ?> All rights reserved © Café Noir Design Inc., 2014.
  46. Turn Off ETags All rights reserved © Café Noir Design

    Inc., 2014.
  47. Resources All rights reserved © Café Noir Design Inc., 2014.

  48. 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/
 All rights reserved © Café Noir Design Inc., 2014.
  49. Closing All rights reserved © Café Noir Design Inc., 2014.

  50. Shannon Smith Web Developer Café Noir Design ! ! www.cafenoirdesign.com

    @cafenoirdesign All rights reserved © Café Noir Design Inc., 2014.