.htaccess 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536
  1. # Apache configuration file
  2. # httpd.apache.org/docs/2.2/mod/quickreference.html
  3. # Note .htaccess files are an overhead, this logic should be in your Apache config if possible
  4. # httpd.apache.org/docs/2.2/howto/htaccess.html
  5. # Techniques in here adapted from all over, including:
  6. # Kroc Camen: camendesign.com/.htaccess
  7. # perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
  8. # Sample .htaccess file of CMS MODx: modxcms.com
  9. ###
  10. ### If you run a webserver other than Apache, consider:
  11. ### github.com/h5bp/server-configs
  12. ###
  13. # ----------------------------------------------------------------------
  14. # Better website experience for IE users
  15. # ----------------------------------------------------------------------
  16. # Force the latest IE version, in various cases when it may fall back to IE7 mode
  17. # github.com/rails/rails/commit/123eb25#commitcomment-118920
  18. # Use ChromeFrame if it's installed for a better experience for the poor IE folk
  19. <IfModule mod_headers.c>
  20. Header set X-UA-Compatible "IE=Edge,chrome=1"
  21. # mod_headers can't match by content-type, but we don't want to send this header on *everything*...
  22. <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|oex|xpi|safariextz|vcf)$" >
  23. Header unset X-UA-Compatible
  24. </FilesMatch>
  25. </IfModule>
  26. # ----------------------------------------------------------------------
  27. # Cross-domain AJAX requests
  28. # ----------------------------------------------------------------------
  29. # Serve cross-domain Ajax requests, disabled by default.
  30. # enable-cors.org
  31. # code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
  32. # <IfModule mod_headers.c>
  33. # Header set Access-Control-Allow-Origin "*"
  34. # </IfModule>
  35. # ----------------------------------------------------------------------
  36. # CORS-enabled images (@crossorigin)
  37. # ----------------------------------------------------------------------
  38. # Send CORS headers if browsers request them; enabled by default for images.
  39. # developer.mozilla.org/en/CORS_Enabled_Image
  40. # blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
  41. # hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
  42. # wiki.mozilla.org/Security/Reviews/crossoriginAttribute
  43. <IfModule mod_setenvif.c>
  44. <IfModule mod_headers.c>
  45. # mod_headers, y u no match by Content-Type?!
  46. <FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
  47. SetEnvIf Origin ":" IS_CORS
  48. Header set Access-Control-Allow-Origin "*" env=IS_CORS
  49. </FilesMatch>
  50. </IfModule>
  51. </IfModule>
  52. # ----------------------------------------------------------------------
  53. # Webfont access
  54. # ----------------------------------------------------------------------
  55. # Allow access from all domains for webfonts.
  56. # Alternatively you could only whitelist your
  57. # subdomains like "subdomain.example.com".
  58. <IfModule mod_headers.c>
  59. <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$">
  60. Header set Access-Control-Allow-Origin "*"
  61. </FilesMatch>
  62. </IfModule>
  63. # ----------------------------------------------------------------------
  64. # Proper MIME type for all files
  65. # ----------------------------------------------------------------------
  66. # JavaScript
  67. # Normalize to standard type (it's sniffed in IE anyways)
  68. # tools.ietf.org/html/rfc4329#section-7.2
  69. AddType application/javascript js
  70. # Audio
  71. AddType audio/ogg oga ogg
  72. AddType audio/mp4 m4a
  73. # Video
  74. AddType video/ogg ogv
  75. AddType video/mp4 mp4 m4v
  76. AddType video/webm webm
  77. # SVG
  78. # Required for svg webfonts on iPad
  79. # twitter.com/FontSquirrel/status/14855840545
  80. AddType image/svg+xml svg svgz
  81. AddEncoding gzip svgz
  82. # Webfonts
  83. AddType application/vnd.ms-fontobject eot
  84. AddType application/x-font-ttf ttf ttc
  85. AddType font/opentype otf
  86. AddType application/x-font-woff woff
  87. # Assorted types
  88. AddType image/x-icon ico
  89. AddType image/webp webp
  90. AddType text/cache-manifest appcache manifest
  91. AddType text/x-component htc
  92. AddType application/x-chrome-extension crx
  93. AddType application/x-opera-extension oex
  94. AddType application/x-xpinstall xpi
  95. AddType application/octet-stream safariextz
  96. AddType application/x-web-app-manifest+json webapp
  97. AddType text/x-vcard vcf
  98. # ----------------------------------------------------------------------
  99. # Allow concatenation from within specific js and css files
  100. # ----------------------------------------------------------------------
  101. # e.g. Inside of script.combined.js you could have
  102. # <!--#include file="libs/jquery-1.5.0.min.js" -->
  103. # <!--#include file="plugins/jquery.idletimer.js" -->
  104. # and they would be included into this single file.
  105. # This is not in use in the boilerplate as it stands. You may
  106. # choose to name your files in this way for this advantage or
  107. # concatenate and minify them manually.
  108. # Disabled by default.
  109. #<FilesMatch "\.combined\.js$">
  110. # Options +Includes
  111. # AddOutputFilterByType INCLUDES application/javascript application/json
  112. # SetOutputFilter INCLUDES
  113. #</FilesMatch>
  114. #<FilesMatch "\.combined\.css$">
  115. # Options +Includes
  116. # AddOutputFilterByType INCLUDES text/css
  117. # SetOutputFilter INCLUDES
  118. #</FilesMatch>
  119. # ----------------------------------------------------------------------
  120. # Gzip compression
  121. # ----------------------------------------------------------------------
  122. <IfModule mod_deflate.c>
  123. # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  124. <IfModule mod_setenvif.c>
  125. <IfModule mod_headers.c>
  126. SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  127. RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  128. </IfModule>
  129. </IfModule>
  130. # HTML, TXT, CSS, JavaScript, JSON, XML, HTC:
  131. <IfModule filter_module>
  132. FilterDeclare COMPRESS
  133. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/html
  134. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/css
  135. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/plain
  136. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/xml
  137. FilterProvider COMPRESS DEFLATE resp=Content-Type $text/x-component
  138. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/javascript
  139. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/json
  140. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xml
  141. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/xhtml+xml
  142. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/rss+xml
  143. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/atom+xml
  144. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/vnd.ms-fontobject
  145. FilterProvider COMPRESS DEFLATE resp=Content-Type $image/svg+xml
  146. FilterProvider COMPRESS DEFLATE resp=Content-Type $image/x-icon
  147. FilterProvider COMPRESS DEFLATE resp=Content-Type $application/x-font-ttf
  148. FilterProvider COMPRESS DEFLATE resp=Content-Type $font/opentype
  149. FilterChain COMPRESS
  150. FilterProtocol COMPRESS DEFLATE change=yes;byteranges=no
  151. </IfModule>
  152. <IfModule !mod_filter.c>
  153. # Legacy versions of Apache
  154. AddOutputFilterByType DEFLATE text/html text/plain text/css application/json
  155. AddOutputFilterByType DEFLATE application/javascript
  156. AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
  157. AddOutputFilterByType DEFLATE application/xhtml+xml application/rss+xml application/atom+xml
  158. AddOutputFilterByType DEFLATE image/x-icon image/svg+xml application/vnd.ms-fontobject application/x-font-ttf font/opentype
  159. </IfModule>
  160. </IfModule>
  161. # ----------------------------------------------------------------------
  162. # Expires headers (for better cache control)
  163. # ----------------------------------------------------------------------
  164. # These are pretty far-future expires headers.
  165. # They assume you control versioning with cachebusting query params like
  166. # <script src="application.js?20100608">
  167. # Additionally, consider that outdated proxies may miscache
  168. # www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
  169. # If you don't use filenames to version, lower the CSS and JS to something like
  170. # "access plus 1 week" or so.
  171. <IfModule mod_expires.c>
  172. ExpiresActive on
  173. # Perhaps better to whitelist expires rules? Perhaps.
  174. ExpiresDefault "access plus 1 month"
  175. # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
  176. ExpiresByType text/cache-manifest "access plus 0 seconds"
  177. # Your document html
  178. ExpiresByType text/html "access plus 0 seconds"
  179. # Data
  180. ExpiresByType text/xml "access plus 0 seconds"
  181. ExpiresByType application/xml "access plus 0 seconds"
  182. ExpiresByType application/json "access plus 0 seconds"
  183. # Feed
  184. ExpiresByType application/rss+xml "access plus 1 hour"
  185. ExpiresByType application/atom+xml "access plus 1 hour"
  186. # Favicon (cannot be renamed)
  187. ExpiresByType image/x-icon "access plus 1 week"
  188. # Media: images, video, audio
  189. ExpiresByType image/gif "access plus 1 month"
  190. ExpiresByType image/png "access plus 1 month"
  191. ExpiresByType image/jpg "access plus 1 month"
  192. ExpiresByType image/jpeg "access plus 1 month"
  193. ExpiresByType video/ogg "access plus 1 month"
  194. ExpiresByType audio/ogg "access plus 1 month"
  195. ExpiresByType video/mp4 "access plus 1 month"
  196. ExpiresByType video/webm "access plus 1 month"
  197. # HTC files (css3pie)
  198. ExpiresByType text/x-component "access plus 1 month"
  199. # Webfonts
  200. ExpiresByType application/x-font-ttf "access plus 1 month"
  201. ExpiresByType font/opentype "access plus 1 month"
  202. ExpiresByType application/x-font-woff "access plus 1 month"
  203. ExpiresByType image/svg+xml "access plus 1 month"
  204. ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  205. # CSS and JavaScript
  206. ExpiresByType text/css "access plus 1 year"
  207. ExpiresByType application/javascript "access plus 1 year"
  208. </IfModule>
  209. # ----------------------------------------------------------------------
  210. # ETag removal
  211. # ----------------------------------------------------------------------
  212. # FileETag None is not enough for every server.
  213. <IfModule mod_headers.c>
  214. Header unset ETag
  215. </IfModule>
  216. # Since we're sending far-future expires, we don't need ETags for
  217. # static content.
  218. # developer.yahoo.com/performance/rules.html#etags
  219. FileETag None
  220. # ----------------------------------------------------------------------
  221. # Stop screen flicker in IE on CSS rollovers
  222. # ----------------------------------------------------------------------
  223. # The following directives stop screen flicker in IE on CSS rollovers - in
  224. # combination with the "ExpiresByType" rules for images (see above). If
  225. # needed, un-comment the following rules.
  226. # BrowserMatch "MSIE" brokenvary=1
  227. # BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
  228. # BrowserMatch "Opera" !brokenvary
  229. # SetEnvIf brokenvary 1 force-no-vary
  230. # ----------------------------------------------------------------------
  231. # Cookie setting from iframes
  232. # ----------------------------------------------------------------------
  233. # Allow cookies to be set from iframes (for IE only)
  234. # If needed, uncomment and specify a path or regex in the Location directive
  235. # <IfModule mod_headers.c>
  236. # <Location />
  237. # Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""
  238. # </Location>
  239. # </IfModule>
  240. # ----------------------------------------------------------------------
  241. # Start rewrite engine
  242. # ----------------------------------------------------------------------
  243. # Turning on the rewrite engine is necessary for the following rules and features.
  244. # FollowSymLinks must be enabled for this to work.
  245. <IfModule mod_rewrite.c>
  246. Options +FollowSymlinks
  247. RewriteEngine On
  248. </IfModule>
  249. # ----------------------------------------------------------------------
  250. # Suppress or force the "www." at the beginning of URLs
  251. # ----------------------------------------------------------------------
  252. # The same content should never be available under two different URLs - especially not with and
  253. # without "www." at the beginning, since this can cause SEO problems (duplicate content).
  254. # That's why you should choose one of the alternatives and redirect the other one.
  255. # By default option 1 (no "www.") is activated. Remember: Shorter URLs are sexier.
  256. # no-www.org/faq.php?q=class_b
  257. # If you rather want to use option 2, just comment out all option 1 lines
  258. # and uncomment option 2.
  259. # IMPORTANT: NEVER USE BOTH RULES AT THE SAME TIME!
  260. # ----------------------------------------------------------------------
  261. # Option 1:
  262. # Rewrite "www.example.com -> example.com"
  263. <IfModule mod_rewrite.c>
  264. RewriteCond %{HTTPS} !=on
  265. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  266. RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  267. </IfModule>
  268. # ----------------------------------------------------------------------
  269. # Option 2:
  270. # To rewrite "example.com -> www.example.com" uncomment the following lines.
  271. # Be aware that the following rule might not be a good idea if you
  272. # use "real" subdomains for certain parts of your website.
  273. # <IfModule mod_rewrite.c>
  274. # RewriteCond %{HTTPS} !=on
  275. # RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  276. # RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  277. # </IfModule>
  278. # ----------------------------------------------------------------------
  279. # Built-in filename-based cache busting
  280. # ----------------------------------------------------------------------
  281. # If you're not using the build script to manage your filename version revving,
  282. # you might want to consider enabling this, which will route requests for
  283. # /css/style.20110203.css to /css/style.css
  284. # To understand why this is important and a better idea than all.css?v1231,
  285. # read: github.com/h5bp/html5-boilerplate/wiki/Version-Control-with-Cachebusting
  286. # Uncomment to enable.
  287. # <IfModule mod_rewrite.c>
  288. # RewriteCond %{REQUEST_FILENAME} !-f
  289. # RewriteCond %{REQUEST_FILENAME} !-d
  290. # RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
  291. # </IfModule>
  292. # ----------------------------------------------------------------------
  293. # Prevent SSL cert warnings
  294. # ----------------------------------------------------------------------
  295. # Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
  296. # https://www.example.com when your cert only allows https://secure.example.com
  297. # Uncomment the following lines to use this feature.
  298. # <IfModule mod_rewrite.c>
  299. # RewriteCond %{SERVER_PORT} !^443
  300. # RewriteRule ^ https://example-domain-please-change-me.com%{REQUEST_URI} [R=301,L]
  301. # </IfModule>
  302. # ----------------------------------------------------------------------
  303. # Prevent 404 errors for non-existing redirected folders
  304. # ----------------------------------------------------------------------
  305. # without -MultiViews, Apache will give a 404 for a rewrite if a folder of the same name does not exist
  306. # e.g. /blog/hello : webmasterworld.com/apache/3808792.htm
  307. Options -MultiViews
  308. # ----------------------------------------------------------------------
  309. # Custom 404 page
  310. # ----------------------------------------------------------------------
  311. # You can add custom pages to handle 500 or 403 pretty easily, if you like.
  312. ErrorDocument 404 /404.html
  313. # ----------------------------------------------------------------------
  314. # UTF-8 encoding
  315. # ----------------------------------------------------------------------
  316. # Use UTF-8 encoding for anything served text/plain or text/html
  317. AddDefaultCharset utf-8
  318. # Force UTF-8 for a number of file formats
  319. AddCharset utf-8 .css .js .xml .json .rss .atom
  320. # ----------------------------------------------------------------------
  321. # A little more security
  322. # ----------------------------------------------------------------------
  323. # Do we want to advertise the exact version number of Apache we're running?
  324. # Probably not.
  325. ## This can only be enabled if used in httpd.conf - It will not work in .htaccess
  326. # ServerTokens Prod
  327. # "-Indexes" will have Apache block users from browsing folders without a default document
  328. # Usually you should leave this activated, because you shouldn't allow everybody to surf through
  329. # every folder on your server (which includes rather private places like CMS system folders).
  330. <IfModule mod_autoindex.c>
  331. Options -Indexes
  332. </IfModule>
  333. # Block access to "hidden" directories whose names begin with a period. This
  334. # includes directories used by version control systems such as Subversion or Git.
  335. <IfModule mod_rewrite.c>
  336. RewriteCond %{SCRIPT_FILENAME} -d
  337. RewriteCond %{SCRIPT_FILENAME} -f
  338. RewriteRule "(^|/)\." - [F]
  339. </IfModule>
  340. # Block access to backup and source files
  341. # This files may be left by some text/html editors and
  342. # pose a great security danger, when someone can access them
  343. <FilesMatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">
  344. Order allow,deny
  345. Deny from all
  346. Satisfy All
  347. </FilesMatch>
  348. # If your server is not already configured as such, the following directive
  349. # should be uncommented in order to set PHP's register_globals option to OFF.
  350. # This closes a major security hole that is abused by most XSS (cross-site
  351. # scripting) attacks. For more information: http://php.net/register_globals
  352. #
  353. # IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS :
  354. #
  355. # Your server does not allow PHP directives to be set via .htaccess. In that
  356. # case you must make this change in your php.ini file instead. If you are
  357. # using a commercial web host, contact the administrators for assistance in
  358. # doing this. Not all servers allow local php.ini files, and they should
  359. # include all PHP configurations (not just this one), or you will effectively
  360. # reset everything to PHP defaults. Consult www.php.net for more detailed
  361. # information about setting PHP directives.
  362. # php_flag register_globals Off
  363. # Rename session cookie to something else, than PHPSESSID
  364. # php_value session.name sid
  365. # Do not show you are using PHP
  366. # Note: Move this line to php.ini since it won't work in .htaccess
  367. # php_flag expose_php Off
  368. # Level of log detail - log all errors
  369. # php_value error_reporting -1
  370. # Write errors to log file
  371. # php_flag log_errors On
  372. # Do not display errors in browser (production - Off, development - On)
  373. # php_flag display_errors Off
  374. # Do not display startup errors (production - Off, development - On)
  375. # php_flag display_startup_errors Off
  376. # Format errors in plain text
  377. # Note: Leave this setting 'On' for xdebug's var_dump() output
  378. # php_flag html_errors Off
  379. # Show multiple occurrence of error
  380. # php_flag ignore_repeated_errors Off
  381. # Show same errors from different sources
  382. # php_flag ignore_repeated_source Off
  383. # Size limit for error messages
  384. # php_value log_errors_max_len 1024
  385. # Don't precede error with string (doesn't accept empty string, use whitespace if you need)
  386. # php_value error_prepend_string " "
  387. # Don't prepend to error (doesn't accept empty string, use whitespace if you need)
  388. # php_value error_append_string " "
  389. # Increase cookie security
  390. <IfModule php5_module>
  391. php_value session.cookie_httponly true
  392. </IfModule>