Modified Drupal 6 .htaccess + HTML5 Boilerplate tweaks


/ Published in: Apache
Save to your folder(s)



Copy this code and paste it in your HTML
  1. # Apache configuration file
  2. # httpd.apache.org/docs/2.2/mod/quickreference.html
  3.  
  4. # Drupal 6 default htaccess file with modifications and techniques from all over, including:
  5. # HTML5 Boilerplate
  6. # Kroc Camen: camendesign.com/.htaccess
  7. # perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
  8.  
  9. # Protect files and directories from prying eyes. (Drupal 6)
  10. <FilesMatch "\.(engine|inc|info|install|make|module|profile|test|po|sh|.*sql|theme|tpl(\.php)?|xtmpl|svn-base)$|^(code-style\.pl|Entries.*|Repository|Root|Tag|Template|all-wcprops|entries|format)$">
  11. Order allow,deny
  12. </FilesMatch>
  13.  
  14. # Force the latest IE version, in various cases when it may fall back to IE7 mode
  15. # github.com/rails/rails/commit/123eb25#commitcomment-118920
  16. # Use ChromeFrame if it's installed for a better experience for the poor IE folk
  17. <IfModule mod_setenvif.c>
  18. <IfModule mod_headers.c>
  19. BrowserMatch MSIE ie
  20. Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie
  21. </IfModule>
  22. </IfModule>
  23.  
  24. <IfModule mod_headers.c>
  25. # Because X-UA-Compatible isn't sent to non-IE (to save header bytes),
  26. # We need to inform proxies that content changes based on UA. (html5-boilerplate)
  27. Header append Vary User-Agent
  28. # Cache control is set only if mod_headers is enabled, so that's unncessary to declare.
  29. </IfModule>
  30.  
  31. # hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/
  32. # Disabled. Uncomment to serve cross-domain ajax requests
  33. #<IfModule mod_headers.c>
  34. # Header set Access-Control-Allow-Origin "*"
  35. #</IfModule>
  36.  
  37.  
  38.  
  39.  
  40. # Allow access from all domains for webfonts. (html5-boilerplate)
  41. # Alternatively you could only whitelist
  42. # your subdomains like "sub.domain.com"
  43.  
  44. <FilesMatch "\.(ttf|otf|eot|woff|font.css)$">
  45. <IfModule mod_headers.c>
  46. Header set Access-Control-Allow-Origin "*"
  47. </IfModule>
  48. </FilesMatch>
  49.  
  50.  
  51. # Video (html5-boilerplate)
  52. AddType video/ogg ogg ogv
  53. AddType video/mp4 mp4
  54. AddType video/webm webm
  55.  
  56. # Proper svg serving. Required for svg webfonts on iPad (html5-boilerplate)
  57. # twitter.com/FontSquirrel/status/14855840545
  58. AddType image/svg+xml svg svgz
  59. AddEncoding gzip svgz
  60.  
  61. # Webfonts (html5-boilerplate)
  62. AddType application/vnd.ms-fontobject eot
  63. AddType font/truetype ttf
  64. AddType font/opentype otf
  65. AddType font/woff woff
  66.  
  67. AddType text/cache-manifest manifest
  68. AddType text/x-component htc
  69.  
  70.  
  71.  
  72. # Don't show directory listings for URLs which map to a directory. (Drupal6)
  73. Options -Indexes
  74.  
  75. # Follow symbolic links in this directory. (Drupal6)
  76. Options +FollowSymLinks
  77.  
  78. # Make Drupal handle any 404 errors. (Drupal6)
  79. ErrorDocument 404 /index.php
  80.  
  81. # Force simple error message for requests for non-existent favicon.ico. (Drupal6)
  82. <Files favicon.ico>
  83. # There is no end quote below, for compatibility with Apache 1.3.
  84. ErrorDocument 404 "The requested file favicon.ico was not found."
  85. </Files>
  86.  
  87. # Set the default handler.
  88. DirectoryIndex index.php
  89.  
  90. # Override PHP settings. More in sites/default/settings.php (Drupal6 + modified)
  91. # but the following cannot be changed at runtime.
  92.  
  93. # PHP 4, Apache 1.
  94. <IfModule mod_php4.c>
  95. php_value magic_quotes_gpc 0
  96. php_value register_globals 0
  97. php_value session.auto_start 0
  98. php_value mbstring.http_input pass
  99. php_value mbstring.http_output pass
  100. php_value mbstring.encoding_translation 0
  101. php_value memory_limit 96M
  102. php_value post_max_size 32M
  103. php_value upload_max_filesize 32M
  104. php_value max_input_time 180
  105. </IfModule>
  106.  
  107. # PHP 4, Apache 2.
  108. <IfModule sapi_apache2.c>
  109. php_value magic_quotes_gpc 0
  110. php_value register_globals 0
  111. php_value session.auto_start 0
  112. php_value mbstring.http_input pass
  113. php_value mbstring.http_output pass
  114. php_value mbstring.encoding_translation 0
  115. php_value memory_limit 25M
  116. php_value post_max_size 32M
  117. php_value upload_max_filesize 32M
  118. php_value max_input_time 180
  119. </IfModule>
  120.  
  121. # PHP 5, Apache 1 and 2.
  122. <IfModule mod_php5.c>
  123. php_value magic_quotes_gpc 0
  124. php_value register_globals 0
  125. php_value session.auto_start 0
  126. php_value mbstring.http_input pass
  127. php_value mbstring.http_output pass
  128. php_value mbstring.encoding_translation 0
  129. # php_value memory_limit 96M
  130. php_value memory_limit 256M
  131. php_value post_max_size 32M
  132. php_value upload_max_filesize 32M
  133. php_value max_input_time 180
  134. </IfModule>
  135.  
  136.  
  137. # Gzip compression. (html5-boilerplate)
  138. <IfModule mod_deflate.c>
  139.  
  140. # html, txt, css, js, json, xml, htc: (html5-boilerplate)
  141. AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json
  142. AddOutputFilterByType DEFLATE text/xml application/xml text/x-component
  143.  
  144. # webfonts and svg: (html5-boilerplate)
  145. <FilesMatch "\.(ttf|otf|eot|svg)$" >
  146. SetOutputFilter DEFLATE
  147. </FilesMatch>
  148. </IfModule>
  149.  
  150.  
  151. # Requires mod_expires to be enabled.
  152. <IfModule mod_expires.c>
  153. # Enable expirations.
  154. ExpiresActive On
  155.  
  156. # Cache all files for 2 weeks after access (A).
  157. ExpiresDefault A1209600
  158.  
  159. <FilesMatch \.php$>
  160. # Do not allow PHP scripts to be cached unless they explicitly send cache
  161. # headers themselves. Otherwise all scripts would have to overwrite the
  162. # headers set by mod_expires if they want another caching behavior. This may
  163. # fail if an error occurs early in the bootstrap process, and it may cause
  164. # problems if a non-Drupal PHP file is installed in a subdirectory.
  165. ExpiresActive Off
  166. </FilesMatch>
  167. </IfModule>
  168.  
  169. # Various rewrite rules.
  170. <IfModule mod_rewrite.c>
  171. RewriteEngine on
  172.  
  173. # If your site can be accessed both with and without the 'www.' prefix, you
  174. # can use one of the following settings to redirect users to your preferred
  175. # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option:
  176. #
  177. # To redirect all users to access the site WITH the 'www.' prefix,
  178. # (http://example.com/... will be redirected to http://www.example.com/...)
  179. # adapt and uncomment the following:
  180. # RewriteCond %{HTTP_HOST} ^example\.com$ [NC]
  181. # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301]
  182. #
  183.  
  184. # Actually, we don't even need to hardcode the domain name if we use the
  185. # following method. (html5-boilerplate)
  186. RewriteCond %{HTTPS} !=on
  187. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  188. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  189.  
  190. # To redirect all users to access the site WITHOUT the 'www.' prefix,
  191. # (http://www.example.com/... will be redirected to http://example.com/...)
  192. # uncomment and adapt the following:
  193. # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC]
  194. # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301]
  195.  
  196. # Modify the RewriteBase if you are using Drupal in a subdirectory or in a
  197. # VirtualDocumentRoot and the rewrite rules are not working properly.
  198. # For example if your site is at http://example.com/drupal uncomment and
  199. # modify the following line:
  200. # RewriteBase /drupal
  201. #
  202. # If your site is running in a VirtualDocumentRoot at http://example.com/,
  203. # uncomment the following line:
  204. RewriteBase /
  205.  
  206. # Rewrite URLs of the form 'x' to the form 'index.php?q=x'.
  207. RewriteCond %{REQUEST_FILENAME} !-f
  208. RewriteCond %{REQUEST_FILENAME} !-d
  209. RewriteCond %{REQUEST_URI} !=/favicon.ico
  210. RewriteRule ^(.*)$ index.php?q=$1 [L,QSA]
  211. </IfModule>
  212.  
  213. # Without -MultiViews, Apache will give a 404 for a rewrite if a folder of the same name does not exist. (html5-boilerplate)
  214. # e.g. /blog/hello : webmasterworld.com/apache/3808792.htm
  215. Options -MultiViews
  216.  
  217. # Use utf-8 encoding for anything served text/plain or text/html. (html5-boilerplate)
  218. AddDefaultCharset utf-8
  219.  
  220. # Force utf-8 for a number of file formats. (html5-boilerplate)
  221. AddCharset utf-8 .html .css .js .xml .json .rss
  222.  
  223. # We don't need to tell everyone we're apache. (html5-boilerplate)
  224. ServerSignature Off
  225.  
  226. # $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.