Last active
December 10, 2015 10:29
-
-
Save ItsMeAra/4421596 to your computer and use it in GitHub Desktop.
.htaccess goodness from: http://net.tutsplus.com/articles/news/htaccess-files-for-the-rest-of-us/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
################################################## | |
# .htaccess Files for the Rest of Us | |
# http://net.tutsplus.com/articles/news/htaccess-files-for-the-rest-of-us/ | |
################################################## | |
# Redirections # | |
# Redirect to new location | |
# Redirect 301 ^old\.html$ http://localhost/new.html | |
##### | |
# Rewrites # | |
# RewriteEngine on | |
# RewriteRule ^old\.html$ new.html | |
# In order to update what is displayed in the address bar of the visitor's browser, | |
# we can use the R flag at the end of the RewriteRule e.g. | |
# | |
# RewriteRule ^old\.html$ http://hostname/new.html [r=301] | |
##### | |
# Serving Custom Error Pages # | |
# ErrorDocument 404 "/404.html" | |
##### | |
# Restricting Access to Specific Resources # | |
# AuthName "Username and password required" | |
# AuthUserFile /path/to/.htpasswd | |
# Require valid-user | |
# AuthType Basic | |
# To protect a specific file, we can wrap the above code | |
# in a <files> directive, which specifies the protected file: | |
# | |
# <Files "protectedfile.html"> | |
# AuthName "Username and password required" | |
# AuthUserFile /path/to/.htpasswd | |
# Require valid-user | |
# AuthType Basic | |
# </Files> | |
##### | |
# Block Access to Certain Entities # | |
# Block IP address: | |
# | |
# order allow,deny | |
# deny from 192.168.0.1 | |
# allow from all | |
# To deny requests based on user-agent, we could do this: | |
# | |
# RewriteCond %{HTTP_USER_AGENT} ^OrangeSpider | |
# RewriteRule ^(.*)$ http://%{REMOTE_ADDR}/$ [r=301,l] | |
##### | |
# Force an IE Rendering Mode # | |
# For example, we can use the mod_headers module, if it is present, to set the X-UA-Compatible header: | |
# | |
# Header set X-UA-Compatible "IE=Edge" | |
# We can also avoid setting this header on files that | |
# don't require it by using a <FilesMatch directive like so: | |
# | |
# <FilesMatch "\.(js|css|gif|png|jpe?g|pdf|xml|oga|ogg|m4a|ogv|mp4|m4v|webm|svg|svgz|eot|ttf|otf|woff|ico|webp|appcache|manifest|htc|crx|xpi|safariextz|vcf)$" > | |
# Header unset X-UA-Compatible | |
# </FilesMatch> | |
##### | |
# Implement Caching # | |
# If you're running your site through Google PageSpeed or Yahoo's YSlow | |
# and you get the message about setting far-future expiry headers, | |
# this is how you fix it: | |
# | |
# ExpiresActive on | |
# ExpiresByType image/gif "access plus 1 month" | |
# ExpiresByType image/png "access plus 1 month" | |
# ExpiresByType image/jpg "access plus 1 month" | |
# ExpiresByType image/jpeg "access plus 1 month" | |
# ExpiresByType video/ogg "access plus 1 month" | |
# ExpiresByType audio/ogg "access plus 1 month" | |
# ExpiresByType video/mp4 "access plus 1 month" | |
# ExpiresByType video/webm "access plus 1 month" | |
##### | |
# Enabling Compression # | |
# This compression scheme works on newer versions of Apache (2.1+) using the mod_filter module | |
# | |
# <IfModule mod_filter> | |
# FilterDeclare COMPRESS | |
# FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html | |
# FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css | |
# FilterProvider COMPRESS DEFLATE resp=Content-Type $text/javascript | |
# FilterChain COMPRESS | |
# FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no | |
# </IfModule> | |
# | |
# On older versions of Apache, the mod_deflate module is used to configure DEFLATE compression. | |
# | |
# <IfModule mod_deflate> | |
# SetOutputFilter DEFLATE | |
# AddOutputFilterByType DEFLATE text/html text/css text/javascript | |
# </IfModule> | |
##### | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment