/ Published in: Apache
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
# Apache configuration file # httpd.apache.org/docs/2.2/mod/quickreference.html # Drupal 6 default htaccess file with modifications and techniques from all over, including: # HTML5 Boilerplate # Kroc Camen: camendesign.com/.htaccess # perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/ # Protect files and directories from prying eyes. (Drupal 6) <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)$"> Order allow,deny </FilesMatch> # Force the latest IE version, in various cases when it may fall back to IE7 mode # github.com/rails/rails/commit/123eb25#commitcomment-118920 # Use ChromeFrame if it's installed for a better experience for the poor IE folk <IfModule mod_setenvif.c> <IfModule mod_headers.c> BrowserMatch MSIE ie Header set X-UA-Compatible "IE=Edge,chrome=1" env=ie </IfModule> </IfModule> <IfModule mod_headers.c> # Because X-UA-Compatible isn't sent to non-IE (to save header bytes), # We need to inform proxies that content changes based on UA. (html5-boilerplate) Header append Vary User-Agent # Cache control is set only if mod_headers is enabled, so that's unncessary to declare. </IfModule> # hacks.mozilla.org/2009/07/cross-site-xmlhttprequest-with-cors/ # Disabled. Uncomment to serve cross-domain ajax requests #<IfModule mod_headers.c> # Header set Access-Control-Allow-Origin "*" #</IfModule> # Allow access from all domains for webfonts. (html5-boilerplate) # Alternatively you could only whitelist # your subdomains like "sub.domain.com" <FilesMatch "\.(ttf|otf|eot|woff|font.css)$"> <IfModule mod_headers.c> Header set Access-Control-Allow-Origin "*" </IfModule> </FilesMatch> # Video (html5-boilerplate) AddType video/ogg ogg ogv AddType video/mp4 mp4 AddType video/webm webm # Proper svg serving. Required for svg webfonts on iPad (html5-boilerplate) # twitter.com/FontSquirrel/status/14855840545 AddType image/svg+xml svg svgz AddEncoding gzip svgz # Webfonts (html5-boilerplate) AddType application/vnd.ms-fontobject eot AddType font/truetype ttf AddType font/opentype otf AddType font/woff woff AddType text/cache-manifest manifest AddType text/x-component htc # Don't show directory listings for URLs which map to a directory. (Drupal6) Options -Indexes # Follow symbolic links in this directory. (Drupal6) Options +FollowSymLinks # Make Drupal handle any 404 errors. (Drupal6) ErrorDocument 404 /index.php # Force simple error message for requests for non-existent favicon.ico. (Drupal6) <Files favicon.ico> # There is no end quote below, for compatibility with Apache 1.3. ErrorDocument 404 "The requested file favicon.ico was not found." </Files> # Set the default handler. DirectoryIndex index.php # Override PHP settings. More in sites/default/settings.php (Drupal6 + modified) # but the following cannot be changed at runtime. # PHP 4, Apache 1. <IfModule mod_php4.c> php_value magic_quotes_gpc 0 php_value register_globals 0 php_value session.auto_start 0 php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.encoding_translation 0 php_value memory_limit 96M php_value post_max_size 32M php_value upload_max_filesize 32M php_value max_input_time 180 </IfModule> # PHP 4, Apache 2. <IfModule sapi_apache2.c> php_value magic_quotes_gpc 0 php_value register_globals 0 php_value session.auto_start 0 php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.encoding_translation 0 php_value memory_limit 25M php_value post_max_size 32M php_value upload_max_filesize 32M php_value max_input_time 180 </IfModule> # PHP 5, Apache 1 and 2. <IfModule mod_php5.c> php_value magic_quotes_gpc 0 php_value register_globals 0 php_value session.auto_start 0 php_value mbstring.http_input pass php_value mbstring.http_output pass php_value mbstring.encoding_translation 0 # php_value memory_limit 96M php_value memory_limit 256M php_value post_max_size 32M php_value upload_max_filesize 32M php_value max_input_time 180 </IfModule> # Gzip compression. (html5-boilerplate) <IfModule mod_deflate.c> # html, txt, css, js, json, xml, htc: (html5-boilerplate) AddOutputFilterByType DEFLATE text/html text/plain text/css text/javascript application/javascript application/json AddOutputFilterByType DEFLATE text/xml application/xml text/x-component # webfonts and svg: (html5-boilerplate) <FilesMatch "\.(ttf|otf|eot|svg)$" > SetOutputFilter DEFLATE </FilesMatch> </IfModule> # Requires mod_expires to be enabled. <IfModule mod_expires.c> # Enable expirations. ExpiresActive On # Cache all files for 2 weeks after access (A). ExpiresDefault A1209600 <FilesMatch \.php$> # Do not allow PHP scripts to be cached unless they explicitly send cache # headers themselves. Otherwise all scripts would have to overwrite the # headers set by mod_expires if they want another caching behavior. This may # fail if an error occurs early in the bootstrap process, and it may cause # problems if a non-Drupal PHP file is installed in a subdirectory. ExpiresActive Off </FilesMatch> </IfModule> # Various rewrite rules. <IfModule mod_rewrite.c> RewriteEngine on # If your site can be accessed both with and without the 'www.' prefix, you # can use one of the following settings to redirect users to your preferred # URL, either WITH or WITHOUT the 'www.' prefix. Choose ONLY one option: # # To redirect all users to access the site WITH the 'www.' prefix, # (http://example.com/... will be redirected to http://www.example.com/...) # adapt and uncomment the following: # RewriteCond %{HTTP_HOST} ^example\.com$ [NC] # RewriteRule ^(.*)$ http://www.example.com/$1 [L,R=301] # # Actually, we don't even need to hardcode the domain name if we use the # following method. (html5-boilerplate) RewriteCond %{HTTPS} !=on RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC] RewriteRule ^(.*)$ http://%1/$1 [R=301,L] # To redirect all users to access the site WITHOUT the 'www.' prefix, # (http://www.example.com/... will be redirected to http://example.com/...) # uncomment and adapt the following: # RewriteCond %{HTTP_HOST} ^www\.example\.com$ [NC] # RewriteRule ^(.*)$ http://example.com/$1 [L,R=301] # Modify the RewriteBase if you are using Drupal in a subdirectory or in a # VirtualDocumentRoot and the rewrite rules are not working properly. # For example if your site is at http://example.com/drupal uncomment and # modify the following line: # RewriteBase /drupal # # If your site is running in a VirtualDocumentRoot at http://example.com/, # uncomment the following line: RewriteBase / # Rewrite URLs of the form 'x' to the form 'index.php?q=x'. RewriteCond %{REQUEST_FILENAME} !-f RewriteCond %{REQUEST_FILENAME} !-d RewriteCond %{REQUEST_URI} !=/favicon.ico RewriteRule ^(.*)$ index.php?q=$1 [L,QSA] </IfModule> # Without -MultiViews, Apache will give a 404 for a rewrite if a folder of the same name does not exist. (html5-boilerplate) # e.g. /blog/hello : webmasterworld.com/apache/3808792.htm Options -MultiViews # Use utf-8 encoding for anything served text/plain or text/html. (html5-boilerplate) AddDefaultCharset utf-8 # Force utf-8 for a number of file formats. (html5-boilerplate) AddCharset utf-8 .html .css .js .xml .json .rss # We don't need to tell everyone we're apache. (html5-boilerplate) ServerSignature Off # $Id: .htaccess,v 1.90.2.5 2010/02/02 07:25:22 dries Exp $