Update README.md

# Accompanies this blog post:
# http://www.seomoz.org/blog/htaccess-file-snippets-for-seos

# NOTE: This file isn't designed to be used all together, some of the rules will conflict,
# it is meant more as a copy and paste board.

# IMPORTANT: Make sure you test .htaccess changes thoroughly, as it can be easy to make mistakes
# and then you end up in a bad place!

RewriteEngine On

#
# 1) Make URLs SEO Friendly and Future Proof
#

<Files magic>
	ForceType application/x-httpd-php5
</Files>


#
# 2) Apply rel="canonical" to PDFs
#

<Files download.pdf>
	Header add Link '<http://www.tomanthony.co.uk/httest/pdf-download.html>; rel="canonical"'
</Files>

<Files product.jpg>
	Header add Link '<http://www.tomanthony.co.uk/httest/product-page.html>; rel="canonical"'
</Files>

RewriteRule ([^/]+)\.pdf$ - [E=FILENAME:$1]
<FilesMatch "\.pdf$">
	Header add Link '<http://www.tomanthony.co.uk/httest/%{FILENAME}e.html>; rel="canonical"'
</FilesMatch>


#
# 3) Robots Directives
#

Header set X-Robots-Tag "noindex, noarchive, nosnippet"


#
# 4) Various Types of Redirect


Redirect Certain pages
redirect 301 /path/to/old-file.php   http://domain.tld/path/to/new-file.php

Old Page to New Page
Redirect 301 /old.html http://www.new-site.com/new.html

To Redirect Entire Site:

Redirect 301 / http://www.new-site.com/

########## Begin 301edirect (www.)olddomain.com to www.example.com
## Note: olddomain.com is your old domain name, you want to redirect FROM,
## whereas www.example.com is the new domain name you want to redirect TO.
## Change those names to reflect your current configuration. Remember, this
## part of the file is supposed to be placed in www.olddomain.com!
## Note: Replace [R=301,L] with [R,L] if you get error 500.
## Uncomment the following lines to enable:
# RewriteCond %{HTTP_HOST} ^(www\.)?olddomain\.com [NC]
# RewriteRule (.*) http://www.example.com/$1 [R=301,L]

# Ensure www on all URLs.
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{HTTP_HOST} ^example.com [NC]
RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
		OR
RewriteRule ^(.*)$ http://www.example.com/$1 [R=301,L]

########## Begin - Redirect non-www to www
RewriteCond %{HTTP_HOST} !^www\. [NC]
RewriteRule ^(.*)$ http://www.%{HTTP_HOST}/$1 [R=301,L]
## If the above throws an HTTP 500 error, swap [R=301,L] with [R,L]

# Ensure we are using HTTPS version of the site.
RewriteCond %{HTTPS} !on
RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI} [L,R=301]

# Ensure all URLs have a trailing slash.
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://www.example.com/$1/ [L,R=301]

# PHP to HTML

RewriteEngine on
RewriteRule ^(.*)\.html$ $1.php [nc]


#
# 5) Custom Error Page
#

ErrorDocument 404 /cool404.html
ErrorDocument 403 /cool403.html
ErrorDocument 500 /cool500.html

# 6)If you don't like Apache's default error pages, create your own, place them in the appropriate directory the example above puts them in a directory called errors which is located in the root of the current web site.
404 Redirect

ErrorDocument 404 http://exmple.com/


#
# 6) Send the Vary Header to Help Crawl Mobile Content
#

Header append Vary: User-Agent



# 7) Improve Caching for Better Site Speed

<FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
	Header set Cache-Control "max-age=28800"
</FilesMatch>

# 1 YEAR
<filesmatch "\.(flv|ico|pdf|avi|mov|ppt|doc|mp3|wmv|wav)$"="">
	Header set Cache-Control "max-age=29030400, public"
</filesmatch>
	 
# 1 WEEK
<filesmatch "\.(jpg|jpeg|png|gif|swf)$"="">
	Header set Cache-Control "max-age=604800, public"
</filesmatch>
	 
# 3 HOUR
<filesmatch "\.(txt|xml|js|css)$"="">
	Header set Cache-Control "max-age=10800"
</filesmatch>
	 
# NEVER CACHE
<filesmatch "\.(html|htm|php|cgi|pl)$"="">
	Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
</filesmatch>
#
# 8) An Apple-style 'Back Soon' Maintenance Page
#

RewriteCond %{REMOTE_ADDR}  !your_ip_address
RewriteCond %{REMOTE_ADDR}  !127.0.0.1
RewriteRule !offline.php$ http://www.example.com/back_soon.html [L,R=307]


#
# 9) Smarten up Your URLs Even When Your CMS Says No!
#

# Rewrite a specific product...
RewriteRule ray-guns/ product.php?id=3123

# ... or groups of them
RewriteRule product/([0-9]+)/ product.php?id=$1


#
# 10)  Recruit via Your HTTP Headers
#

Header set Hiring-Now "Looking for a job? Email us!"


# 11) blocking hotlinking

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://www.mysite.com/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$ http://www.mysite.com/bad.gif [R]

#The first line tells Apache to use the rewrite engine, a module that not all web hosts support (most do). The second and third say that if no referer is not given, or if the user is not referred by your site, to do what's in the fourth line - to substitute the file bad.gif (in the root folder, that is, the highest folder in the site) for any GIF or JPG file. In short, if a person did not type in a photo's address directly into their browser or reach it from your site, Apache will automatically put in a specific image of your choosing. In my case, bad.gif is a little ad for my site; it's a two-color (red on white) file that weighs in at a mere 1.6K.

#If your site is not set up (as mine is) to automatically put "www" in front of any web requests (so that rootes-chrysler.co.uk is automatically turned into www.rootes-chrysler.co.uk), you'll want an extra line to cover the "non-www" requests:

RewriteEngine on
RewriteCond %{HTTP_REFERER} !^$
RewriteCond %{HTTP_REFERER} !^http://rootes-chrysler.co.uk/.*$ [NC]
RewriteCond %{HTTP_REFERER} !^http://www.rootes-chrysler.co.uk/.*$ [NC]
RewriteRule .*\.(gif|GIF|jpg|JPG)$ http://www.rootes-chrysler.co.uk/bad.gif [R]


#12) Add future Expires

<ifModule mod_expires.c>
  ExpiresActive On
  ExpiresDefault "access plus 1 seconds"
  ExpiresByType text/html "access plus 1 seconds"
  ExpiresByType image/gif "access plus 2592000 seconds"
  ExpiresByType image/jpeg "access plus 2592000 seconds"
  ExpiresByType image/png "access plus 2592000 seconds"
  ExpiresByType text/css "access plus 604800 seconds"
  ExpiresByType text/javascript "access plus 216000 seconds"
  ExpiresByType application/x-javascript "access plus 216000 seconds"
</ifModule>


#13) Turn off ETags and Remove Last-Modified header

<IfModule mod_headers.c>
    Header unset ETag
    Header unset Last-Modified
</IfModule>

<FilesMatch "\.(ico|gif|jpg|jpeg|png|swf|css|js|html?|xml|txt)$">
	FileETag none
</FilesMatch>

#By removing the ETag header, you disable caches and browsers from being able to validate files, so they are forced to rely on your Cache-Control and Expires header.
Entity tags (ETags) are a mechanism to check for a newer version of a cached file.

#If you remove the Last-Modified and ETag header, you will totally eliminate If-Modified-Since and If-None-Match requests and their 304 Not Modified responses, so a file will stay cached without checking for updates until the Expires header indicates new content is available!


#Notes
With these settings you should have your site a lot faster and your file’s size greatly reduced.

#15) Enabling mod_deflate (gzip compression) in .htaccess

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
</IfModule>

#Example with browser type:

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE text/text text/html text/plain text/xml text/css application/x-javascript application/javascript
SetEnvIfNoCase Request_URI .(?:exe|t?gz|zip|iso|tar|bz2|sit|rar|png|jpg|gif|jpeg|flv|swf)$ no-gzip dont-vary
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.[0678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent env=!dont-vary
</IfModule>


#Second example Gzip - compress text, html, javascript, css, xml
<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript
</ifmodule>



# 16) Site Under Maintenance

Options +FollowSymlinks
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteRule .* /maintenance.html [L]

#Is your site going into maintenance? If so place this in your htaccess. When you are done with maintenance just comment it out with the # symbol. You will also need to make the page maintenance.html which will be displayed to visitors.

#(You can replace [L] with [R=307,L] if you prefer that the user see from the URL that they've been redirected to a maintenance page, but this is usually not what you want. If you don't use the redirect option, the URL will remain unaltered in the browser, and after you turn off maintenance mode, when the user refreshes, they'll see the original page they were trying to access.)


# 17 SEO and User friendly url

<IfModule mod_rewrite.c>
RewriteEngine on

# Some hosts need a RewriteBase specification.
RewriteBase /MyBB/

# Google SEO workaround for search.php highlights:
# Make this rule the first rewrite rule in your .htaccess!
RewriteRule ^([^&]*)&(.*)$ http://yoursite/MyBB/$1?$2 [L,QSA,R=301]

# Google SEO Sitemap:
RewriteRule ^sitemap-([^./]+)\.xml$ misc.php?google_seo_sitemap=$1 [L,QSA,NC]

# Google SEO URL Forums:
RewriteRule ^Forum-([^./]+)$ forumdisplay.php?google_seo_forum=$1 [L,QSA,NC]

# Google SEO URL Threads:
RewriteRule ^Thread-([^./]+)$ showthread.php?google_seo_thread=$1 [L,QSA,NC]

# Google SEO URL Announcements:
RewriteRule ^Announcement-([^./]+)$ announcements.php?google_seo_announcement=$1 [L,QSA,NC]

# Google SEO URL Users:
RewriteRule ^User-([^./]+)$ member.php?action=profile&google_seo_user=$1 [L,QSA,NC]

# Google SEO URL Calendars:
RewriteRule ^Calendar-([^./]+)$ calendar.php?google_seo_calendar=$1 [L,QSA,NC]

# Google SEO URL Events:
RewriteRule ^Event-([^./]+)$ calendar.php?action=event&google_seo_event=$1 [L,QSA,NC]

# Google SEO 404:
ErrorDocument 404 /MyBB/misc.php?google_seo_error=404

# Default MyBB Rewrite Rules:
RewriteRule ^forum-([0-9]+)\.html$ forumdisplay.php?fid=$1 [L,QSA]
RewriteRule ^forum-([0-9]+)-page-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2 [L,QSA]

RewriteRule ^thread-([0-9]+)\.html$ showthread.php?tid=$1 [L,QSA]
RewriteRule ^thread-([0-9]+)-page-([0-9]+)\.html$ showthread.php?tid=$1&page=$2 [L,QSA]
RewriteRule ^thread-([0-9]+)-lastpost\.html$ showthread.php?tid=$1&action=lastpost [L,QSA]
RewriteRule ^thread-([0-9]+)-nextnewest\.html$ showthread.php?tid=$1&action=nextnewest [L,QSA]
RewriteRule ^thread-([0-9]+)-nextoldest\.html$ showthread.php?tid=$1&action=nextoldest [L,QSA]
RewriteRule ^thread-([0-9]+)-newpost\.html$ showthread.php?tid=$1&action=newpost [L,QSA]
RewriteRule ^thread-([0-9]+)-post-([0-9]+)\.html$ showthread.php?tid=$1&pid=$2 [L,QSA]

RewriteRule ^post-([0-9]+)\.html$ showthread.php?pid=$1 [L,QSA]

RewriteRule ^announcement-([0-9]+)\.html$ announcements.php?aid=$1 [L,QSA]

RewriteRule ^user-([0-9]+)\.html$ member.php?action=profile&uid=$1 [L,QSA]

RewriteRule ^calendar-([0-9]+)\.html$ calendar.php?calendar=$1 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)\.html$ calendar.php?action=yearview&calendar=$1&year=$2 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)\.html$ calendar.php?calendar=$1&year=$2&month=$3 [L,QSA]
RewriteRule ^calendar-([0-9]+)-year-([0-9]+)-month-([0-9]+)-day-([0-9]+)\.html$ calendar.php?action=dayview&calendar=$1&year=$2&month=$3&day=$4 [L,QSA]
RewriteRule ^calendar-([0-9]+)-week-(n?[0-9]+)\.html$ calendar.php?action=weekview&calendar=$1&week=$2 [L,QSA]

RewriteRule ^event-([0-9]+)\.html$ calendar.php?action=event&eid=$1 [L,QSA]

<IfModule mod_env.c>
SetEnv SEO_SUPPORT 1
</IfModule>
</IfModule>

Second example
RewriteEngine on
RewriteRule txtxtxtx7/$ ./imgxkm/index.php?p=t
RewriteRule teletubbies-mercy-kill/$ ./imgxkm/index.php?p=7394990
RewriteRule preppy-fairies/$ ./imgxkm/index.php?p=7395160
RewriteRule online-1st-garder-games/$ ./imgxkm/index.php?p=7395330
RewriteRule seattle-samantha-ronson-dj/$ ./imgxkm/index.php?p=7395500
RewriteRule book-review-lucy-doesn't-wear-pink/$ ./imgxkm/index.php?p=7395670
RewriteRule kenneth-rahn-maeystown-illinois-died-2010/$ ./imgxkm/index.php?p=7395840
RewriteRule morris-forced-swim-model/$ ./imgxkm/index.php?p=7396010
RewriteRule hugo-dominguez-crime/$ ./imgxkm/index.php?p=7396180
RewriteRule 98-oldsmobile-bravada-water-leak/$ ./imgxkm/index.php?p=7396350
RewriteRule anymore-wikileaks-since-assange-arrest/$ ./imgxkm/index.php?p=7396520
RewriteRule eugenics-videos/$ ./imgxkm/index.php?p=7396690
RewriteRule 2008-cimarron-norstar-3-horse/$ ./imgxkm/index.php?p=7396860
RewriteRule rotary-bedder/$ ./imgxkm/index.php?p=7397030
RewriteRule wilmington-massachusetts-real-estate-in-foreclosure/$ ./imgxkm/index.php?p=7397200
RewriteRule cutting-rinsing-pineapples-in-salt/$ ./imgxkm/index.php?p=7397370
RewriteRule dinar-iraq/$ ./imgxkm/index.php?p=7397540
RewriteRule zalman-9700-nt-maximus/$ ./imgxkm/index.php?p=7397710
RewriteRule pastrami-and-saurkraut-cheese-sandwiches/$ ./imgxkm/index.php?p=7397880
RewriteRule us-voter-registration-by-politcal-party/$ ./imgxkm/index.php?p=7398050
RewriteRule gerhard-kawaschinski/$ ./imgxkm/index.php?p=7398220
RewriteRule redtube-hotties-pics/$ ./imgxkm/index.php?p=7398390
RewriteRule stores-nostalgia-bucks-county/$ ./imgxkm/index.php?p=7398560
RewriteRule hypocrisy-in-the-scarlet-letter/$ ./imgxkm/index.php?p=7398730
RewriteRule brutus-skid-tire/$ ./imgxkm/index.php?p=7398900
RewriteRule panasonic-cr-2450-3v/$ ./imgxkm/index.php?p=7399070
RewriteRule bogs-in-new-york/$ ./imgxkm/index.php?p=7399240
RewriteRule landen-apartments/$ ./imgxkm/index.php?p=7399410
RewriteRule pro-bono-military-lawyer/$ ./imgxkm/index.php?p=7399580


#Third Example
# Google SEO Sitemap:
"^/MyBB/((?i)sitemap-([^./?]+)\.xml)(\?(.*)|)$" => "/MyBB/misc.php?google_seo_sitemap=$2&$4",

# Google SEO URL Forums:
"^/MyBB/((?i)Forum-([^./?]+))(\?(.*)|)$" => "/MyBB/forumdisplay.php?google_seo_forum=$2&$4",

# Google SEO URL Threads:
"^/MyBB/((?i)Thread-([^./?]+))(\?(.*)|)$" => "/MyBB/showthread.php?google_seo_thread=$2&$4",

# Google SEO URL Announcements:
"^/MyBB/((?i)Announcement-([^./?]+))(\?(.*)|)$" => "/MyBB/announcements.php?google_seo_announcement=$2&$4",

# Google SEO URL Users:
"^/MyBB/((?i)User-([^./?]+))(\?(.*)|)$" => "/MyBB/member.php?action=profile&google_seo_user=$2&$4",

# Google SEO URL Calendars:
"^/MyBB/((?i)Calendar-([^./?]+))(\?(.*)|)$" => "/MyBB/calendar.php?google_seo_calendar=$2&$4",

# Google SEO URL Events:
"^/MyBB/((?i)Event-([^./?]+))(\?(.*)|)$" => "/MyBB/calendar.php?action=event&google_seo_event=$2&$4",