Skip to content

Instantly share code, notes, and snippets.

@tcelestino
Last active August 29, 2015 14:22
Show Gist options
  • Save tcelestino/c03bb55ef5ff971a21c4 to your computer and use it in GitHub Desktop.
Save tcelestino/c03bb55ef5ff971a21c4 to your computer and use it in GitHub Desktop.
tips for .htaccess
# remove www
RewriteEngine On
RewriteCond %{HTTP_HOST} !^meusite.com$ [NC]
RewriteRule ^(.*)$ http://meusite.com/$1 [L,R=301]
# add hotlinking
RewriteEngine On
#Replace ?mysite.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+.)?meusite.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]
# redirect rss to feedburner
<IfModule mod_alias.c>
RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/
RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://feedburner.com/yourfeed/
</IfModule>
# custom pages
ErrorDocument 400 /errors/badrequest.html
ErrorDocument 401 /errors/authreqd.html
ErrorDocument 403 /errors/forbid.html
ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/serverr.html
# force download files
<Files *.xls>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
<Files *.eps>
ForceType application/octet-stream
Header set Content-Disposition attachment
</Files>
# remove extensions
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_FILENAME}.html -f
RewriteRule ^(.*)$ $1.html
# Replace html with your file extension, eg: php, htm, asp
# hide list directories
Options -Indexes
# utf-8 all files
<FilesMatch ".(htm|html|css|js)$">
AddDefaultCharset UTF-8
</FilesMatch>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment