Advertisement
n0aX

.htaccess

Nov 10th, 2012
45
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1.  
  2. # Apache configuration file
  3. # httpd.apache.org/docs/2.2/mod/quickreference.html
  4.  
  5. # Note .htaccess files are an overhead, this logic should be in your Apache
  6. # config if possible: httpd.apache.org/docs/2.2/howto/htaccess.html
  7.  
  8. # Techniques in here adapted from all over, including:
  9. #   Kroc Camen: camendesign.com/.htaccess
  10. #   perishablepress.com/press/2006/01/10/stupid-htaccess-tricks/
  11. #   Sample .htaccess file of CMS MODx: modxcms.com
  12.  
  13.  
  14. # ----------------------------------------------------------------------
  15. # Better website experience for IE users
  16. # ----------------------------------------------------------------------
  17.  
  18. # Force the latest IE version, in various cases when it may fall back to IE7 mode
  19. #  github.com/rails/rails/commit/123eb25#commitcomment-118920
  20. # Use ChromeFrame if it's installed for a better experience for the poor IE folk
  21.  
  22. <IfModule mod_headers.c>
  23.  Header set X-UA-Compatible "IE=Edge,chrome=1"
  24.  Header unset Expires
  25.  Header unset Cache-Control
  26.  # mod_headers can't match by content-type, but we don't want to send this header on *everything*...
  27.  <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)$" >
  28.    Header unset X-UA-Compatible
  29.  </FilesMatch>
  30. </IfModule>
  31.  
  32.  
  33. # ----------------------------------------------------------------------
  34. # Cross-domain AJAX requests
  35. # ----------------------------------------------------------------------
  36.  
  37. # Serve cross-domain Ajax requests, disabled by default.
  38. # enable-cors.org
  39. # code.google.com/p/html5security/wiki/CrossOriginRequestSecurity
  40.  
  41. #  <IfModule mod_headers.c>
  42. #    Header set Access-Control-Allow-Origin "*"
  43. #  </IfModule>
  44.  
  45.  
  46. # ----------------------------------------------------------------------
  47. # CORS-enabled images (@crossorigin)
  48. # ----------------------------------------------------------------------
  49.  
  50. # Send CORS headers if browsers request them; enabled by default for images.
  51. # developer.mozilla.org/en/CORS_Enabled_Image
  52. # blog.chromium.org/2011/07/using-cross-domain-images-in-webgl-and.html
  53. # hacks.mozilla.org/2011/11/using-cors-to-load-webgl-textures-from-cross-domain-images/
  54. # wiki.mozilla.org/Security/Reviews/crossoriginAttribute
  55.  
  56. <IfModule mod_setenvif.c>
  57.  <IfModule mod_headers.c>
  58.    # mod_headers, y u no match by Content-Type?!
  59.    <FilesMatch "\.(gif|png|jpe?g|svg|svgz|ico|webp)$">
  60.      SetEnvIf Origin ":" IS_CORS
  61.      Header set Access-Control-Allow-Origin "*" env=IS_CORS
  62.    </FilesMatch>
  63.  </IfModule>
  64. </IfModule>
  65.  
  66.  
  67. # ----------------------------------------------------------------------
  68. # Webfont access
  69. # ----------------------------------------------------------------------
  70.  
  71. # Allow access from all domains for webfonts.
  72. # Alternatively you could only whitelist your
  73. # subdomains like "subdomain.example.com".
  74.  
  75. <IfModule mod_headers.c>
  76.  <FilesMatch "\.(ttf|ttc|otf|eot|woff|font.css)$">
  77.    Header set Access-Control-Allow-Origin "*"
  78.  </FilesMatch>
  79. </IfModule>
  80.  
  81.  
  82. # ----------------------------------------------------------------------
  83. # Proper MIME type for all files
  84. # ----------------------------------------------------------------------
  85.  
  86. # JavaScript
  87. #   Normalize to standard type (it's sniffed in IE anyways)
  88. #   tools.ietf.org/html/rfc4329#section-7.2
  89. AddType application/javascript         js jsonp
  90. AddType application/json               json
  91.  
  92. # Audio
  93. AddType audio/ogg                      oga ogg
  94. AddType audio/mp4                      m4a f4a f4b
  95.  
  96. # Video
  97. AddType video/ogg                      ogv
  98. AddType video/mp4                      mp4 m4v f4v f4p
  99. AddType video/webm                     webm
  100. AddType video/x-flv                    flv
  101.  
  102. # SVG
  103. #   Required for svg webfonts on iPad
  104. #   twitter.com/FontSquirrel/status/14855840545
  105. AddType     image/svg+xml              svg svgz
  106. AddEncoding gzip                       svgz
  107.  
  108. # Webfonts
  109. AddType application/vnd.ms-fontobject  eot
  110. AddType application/x-font-ttf         ttf ttc
  111. AddType font/opentype                  otf
  112. AddType application/x-font-woff        woff
  113.  
  114. # Assorted types
  115. AddType image/x-icon                        ico
  116. AddType image/webp                          webp
  117. AddType text/cache-manifest                 appcache manifest
  118. AddType text/x-component                    htc
  119. AddType application/xml                     rss atom xml rdf
  120. AddType application/x-chrome-extension      crx
  121. AddType application/x-opera-extension       oex
  122. AddType application/x-xpinstall             xpi
  123. AddType application/octet-stream            safariextz
  124. AddType application/x-web-app-manifest+json webapp
  125. AddType text/x-vcard                        vcf
  126. AddType application/x-shockwave-flash       swf
  127. AddType text/vtt                            vtt
  128.  
  129.  
  130. # ----------------------------------------------------------------------
  131. # Allow concatenation from within specific js and css files
  132. # ----------------------------------------------------------------------
  133.  
  134. # e.g. Inside of script.combined.js you could have
  135. #   <!--#include file="libs/jquery-1.5.0.min.js" -->
  136. #   <!--#include file="plugins/jquery.idletimer.js" -->
  137. # and they would be included into this single file.
  138.  
  139. # This is not in use in the boilerplate as it stands. You may
  140. # choose to use this technique if you do not have a build process.
  141.  
  142. #<FilesMatch "\.combined\.js$">
  143. #  Options +Includes
  144. #  AddOutputFilterByType INCLUDES application/javascript application/json
  145. #  SetOutputFilter INCLUDES
  146. #</FilesMatch>
  147.  
  148. #<FilesMatch "\.combined\.css$">
  149. #  Options +Includes
  150. #  AddOutputFilterByType INCLUDES text/css
  151. #  SetOutputFilter INCLUDES
  152. #</FilesMatch>
  153.  
  154.  
  155. # ----------------------------------------------------------------------
  156. # Gzip compression
  157. # ----------------------------------------------------------------------
  158.  
  159. <IfModule mod_deflate.c>
  160.  
  161.   # Force deflate for mangled headers developer.yahoo.com/blogs/ydn/posts/2010/12/pushing-beyond-gzipping/
  162.   <IfModule mod_setenvif.c>
  163.     <IfModule mod_headers.c>
  164.       SetEnvIfNoCase ^(Accept-EncodXng|X-cept-Encoding|X{15}|~{15}|-{15})$ ^((gzip|deflate)\s*,?\s*)+|[X~-]{4,13}$ HAVE_Accept-Encoding
  165.       RequestHeader append Accept-Encoding "gzip,deflate" env=HAVE_Accept-Encoding
  166.     </IfModule>
  167.   </IfModule>
  168.  
  169.   # Compress all output labeled with one of the following MIME-types
  170.   <IfModule mod_filter.c>
  171.     AddOutputFilterByType DEFLATE application/atom+xml \
  172.                                   application/javascript \
  173.                                   application/json \
  174.                                   application/rss+xml \
  175.                                   application/vnd.ms-fontobject \
  176.                                   application/x-font-ttf \
  177.                                   application/xhtml+xml \
  178.                                   application/xml \
  179.                                   font/opentype \
  180.                                   image/svg+xml \
  181.                                   image/x-icon \
  182.                                   text/css \
  183.                                   text/html \
  184.                                   text/plain \
  185.                                   text/x-component \
  186.                                   text/xml
  187.   </IfModule>
  188.  
  189. </IfModule>
  190.  
  191.  
  192. # ----------------------------------------------------------------------
  193. # Expires headers (for better cache control)
  194. # ----------------------------------------------------------------------
  195.  
  196. # These are pretty far-future expires headers.
  197. # They assume you control versioning with filename-based cache busting
  198. # Additionally, consider that outdated proxies may miscache
  199. #   www.stevesouders.com/blog/2008/08/23/revving-filenames-dont-use-querystring/
  200.  
  201. # If you don't use filenames to version, lower the CSS and JS to something like
  202. # "access plus 1 week".
  203.  
  204. <IfModule mod_expires.c>
  205.  ExpiresActive on
  206.  
  207. # Perhaps better to whitelist expires rules? Perhaps.
  208.  ExpiresDefault                          "access plus 1 month"
  209.  
  210. # cache.appcache needs re-requests in FF 3.6 (thanks Remy ~Introducing HTML5)
  211.  ExpiresByType text/cache-manifest       "access plus 0 seconds"
  212.  
  213. # Your document html
  214.  ExpiresByType text/html                 "access plus 0 seconds"
  215.  
  216. # Data
  217.  ExpiresByType text/xml                  "access plus 0 seconds"
  218.  ExpiresByType application/xml           "access plus 0 seconds"
  219.  ExpiresByType application/json          "access plus 0 seconds"
  220.  
  221. # Feed
  222.  ExpiresByType application/rss+xml       "access plus 1 hour"
  223.  ExpiresByType application/atom+xml      "access plus 1 hour"
  224.  
  225. # Favicon (cannot be renamed)
  226.  ExpiresByType image/x-icon              "access plus 1 week"
  227.  
  228. # Media: images, video, audio
  229.  ExpiresByType image/gif                 "access plus 1 month"
  230.  ExpiresByType image/png                 "access plus 1 month"
  231.  ExpiresByType image/jpeg                "access plus 1 month"
  232.  ExpiresByType video/ogg                 "access plus 1 month"
  233.  ExpiresByType audio/ogg                 "access plus 1 month"
  234.  ExpiresByType video/mp4                 "access plus 1 month"
  235.  ExpiresByType video/webm                "access plus 1 month"
  236.  
  237. # HTC files  (css3pie)
  238.  ExpiresByType text/x-component          "access plus 1 month"
  239.  
  240. # Webfonts
  241.  ExpiresByType application/x-font-ttf    "access plus 1 month"
  242.  ExpiresByType font/opentype             "access plus 1 month"
  243.  ExpiresByType application/x-font-woff   "access plus 1 month"
  244.  ExpiresByType image/svg+xml             "access plus 1 month"
  245.  ExpiresByType application/vnd.ms-fontobject "access plus 1 month"
  246.  
  247. # CSS and JavaScript
  248.  ExpiresByType text/css                  "access plus 1 year"
  249.  ExpiresByType application/javascript    "access plus 1 year"
  250.  
  251. </IfModule>
  252.  
  253.  
  254. # ----------------------------------------------------------------------
  255. # Prevent mobile network providers from modifying your site
  256. # ----------------------------------------------------------------------
  257.  
  258. # The following header prevents modification of your code over 3G on some
  259. # European providers.
  260. # This is the official 'bypass' suggested by O2 in the UK.
  261.  
  262. # <IfModule mod_headers.c>
  263. # Header set Cache-Control "no-transform"
  264. # </IfModule>
  265.  
  266.  
  267. # ----------------------------------------------------------------------
  268. # ETag removal
  269. # ----------------------------------------------------------------------
  270.  
  271. # FileETag None is not enough for every server.
  272. <IfModule mod_headers.c>
  273.  Header unset ETag
  274. </IfModule>
  275.  
  276. # Since we're sending far-future expires, we don't need ETags for
  277. # static content.
  278. #   developer.yahoo.com/performance/rules.html#etags
  279. FileETag None
  280.  
  281.  
  282. # ----------------------------------------------------------------------
  283. # Stop screen flicker in IE on CSS rollovers
  284. # ----------------------------------------------------------------------
  285.  
  286. # The following directives stop screen flicker in IE on CSS rollovers - in
  287. # combination with the "ExpiresByType" rules for images (see above).
  288.  
  289. # BrowserMatch "MSIE" brokenvary=1
  290. # BrowserMatch "Mozilla/4.[0-9]{2}" brokenvary=1
  291. # BrowserMatch "Opera" !brokenvary
  292. # SetEnvIf brokenvary 1 force-no-vary
  293.  
  294.  
  295. # ----------------------------------------------------------------------
  296. # Set Keep-Alive Header
  297. # ----------------------------------------------------------------------
  298.  
  299. # Keep-Alive allows the server to send multiple requests through one
  300. # TCP-connection. Be aware of possible disadvantages of this setting. Turn on
  301. # if you serve a lot of static content.
  302.  
  303. # <IfModule mod_headers.c>
  304. #   Header set Connection Keep-Alive
  305. # </IfModule>
  306.  
  307.  
  308. # ----------------------------------------------------------------------
  309. # Cookie setting from iframes
  310. # ----------------------------------------------------------------------
  311.  
  312. # Allow cookies to be set from iframes (for IE only)
  313. # If needed, specify a path or regex in the Location directive.
  314.  
  315. # <IfModule mod_headers.c>
  316. #   Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"IDC DSP COR ADM DEVi TAIi PSA PSD IVAi IVDi CONi HIS OUR IND CNT\""
  317. # </IfModule>
  318.  
  319.  
  320. # ----------------------------------------------------------------------
  321. # Start rewrite engine
  322. # ----------------------------------------------------------------------
  323.  
  324. # Turning on the rewrite engine is necessary for the following rules and
  325. # features. FollowSymLinks must be enabled for this to work.
  326.  
  327. # Some cloud hosting services require RewriteBase to be set: goo.gl/HOcPN
  328. # If using the h5bp in a subdirectory, use `RewriteBase /foo` instead where
  329. # 'foo' is your directory.
  330.  
  331. # If your web host doesn't allow the FollowSymlinks option, you may need to
  332. # comment it out and use `Options +SymLinksOfOwnerMatch`, but be aware of the
  333. # performance impact: http://goo.gl/Mluzd
  334.  
  335. <IfModule mod_rewrite.c>
  336.   Options +FollowSymlinks
  337. # Options +SymLinksIfOwnerMatch
  338.   RewriteEngine On
  339. # RewriteBase /
  340. </IfModule>
  341.  
  342.  
  343. # ----------------------------------------------------------------------
  344. # Suppress or force the "www." at the beginning of URLs
  345. # ----------------------------------------------------------------------
  346.  
  347. # The same content should never be available under two different URLs -
  348. # especially not with and without "www." at the beginning, since this can cause
  349. # SEO problems (duplicate content). That's why you should choose one of the
  350. # alternatives and redirect the other one.
  351.  
  352. # By default option 1 (no "www.") is activated.
  353. # no-www.org/faq.php?q=class_b
  354.  
  355. # If you'd prefer to use option 2, just comment out all option 1 lines
  356. # and uncomment option 2.
  357.  
  358. # IMPORTANT: NEVER USE BOTH RULES AT THE SAME TIME!
  359.  
  360. # ----------------------------------------------------------------------
  361.  
  362. # Option 1:
  363. # Rewrite "www.example.com -> example.com".
  364.  
  365. #<IfModule mod_rewrite.c>
  366.  # RewriteCond %{HTTPS} !=on
  367.   #RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  368.   #RewriteRule ^ http://%1%{REQUEST_URI} [R=301,L]
  369. #</IfModule>
  370.  
  371. # ----------------------------------------------------------------------
  372.  
  373. # Option 2:
  374. # Rewrite "example.com -> www.example.com".
  375. # Be aware that the following rule might not be a good idea if you use "real"
  376. # subdomains for certain parts of your website.
  377.  
  378. # <IfModule mod_rewrite.c>
  379. #   RewriteCond %{HTTPS} !=on
  380. #   RewriteCond %{HTTP_HOST} !^www\..+$ [NC]
  381. #   RewriteRule ^ http://www.%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
  382. # </IfModule>
  383.  
  384.  
  385. # ----------------------------------------------------------------------
  386. # Built-in filename-based cache busting
  387. # ----------------------------------------------------------------------
  388.  
  389. # If you're not using the build script to manage your filename version revving,
  390. # you might want to consider enabling this, which will route requests for
  391. # /css/style.20110203.css to /css/style.css
  392.  
  393. # To understand why this is important and a better idea than all.css?v1231,
  394. # read: github.com/h5bp/html5-boilerplate/wiki/cachebusting
  395.  
  396. # <IfModule mod_rewrite.c>
  397. #   RewriteCond %{REQUEST_FILENAME} !-f
  398. #   RewriteCond %{REQUEST_FILENAME} !-d
  399. #   RewriteRule ^(.+)\.(\d+)\.(js|css|png|jpg|gif)$ $1.$3 [L]
  400. # </IfModule>
  401.  
  402.  
  403. # ----------------------------------------------------------------------
  404. # Prevent SSL cert warnings
  405. # ----------------------------------------------------------------------
  406.  
  407. # Rewrite secure requests properly to prevent SSL cert warnings, e.g. prevent
  408. # https://www.example.com when your cert only allows https://secure.example.com
  409.  
  410. # <IfModule mod_rewrite.c>
  411. #   RewriteCond %{SERVER_PORT} !^443
  412. #   RewriteRule ^ https://example-domain-please-change-me.com%{REQUEST_URI} [R=301,L]
  413. # </IfModule>
  414.  
  415.  
  416. # ----------------------------------------------------------------------
  417. # Prevent 404 errors for non-existing redirected folders
  418. # ----------------------------------------------------------------------
  419.  
  420. # without -MultiViews, Apache will give a 404 for a rewrite if a folder of the
  421. # same name does not exist.
  422. # webmasterworld.com/apache/3808792.htm
  423.  
  424. Options -MultiViews
  425.  
  426.  
  427. # ----------------------------------------------------------------------
  428. # Custom 404 page
  429. # ----------------------------------------------------------------------
  430.  
  431. # You can add custom pages to handle 500 or 403 pretty easily, if you like.
  432. # If you are hosting your site in subdirectory, adjust this accordingly
  433. #    e.g. ErrorDocument 404 /subdir/404.html
  434. #ErrorDocument 404 /404.html
  435.  
  436.  
  437. # ----------------------------------------------------------------------
  438. # UTF-8 encoding
  439. # ----------------------------------------------------------------------
  440.  
  441. # Use UTF-8 encoding for anything served text/plain or text/html
  442. AddDefaultCharset utf-8
  443.  
  444. # Force UTF-8 for a number of file formats
  445. AddCharset utf-8 .atom .css .js .json .rss .vtt .xml
  446.  
  447.  
  448. # ----------------------------------------------------------------------
  449. # A little more security
  450. # ----------------------------------------------------------------------
  451.  
  452. # To avoid displaying the exact version number of Apache being used, add the
  453. # following to httpd.conf (it will not work in .htaccess):
  454. # ServerTokens Prod
  455.  
  456. # "-Indexes" will have Apache block users from browsing folders without a
  457. # default document Usually you should leave this activated, because you
  458. # shouldn't allow everybody to surf through every folder on your server (which
  459. # includes rather private places like CMS system folders).
  460. <IfModule mod_autoindex.c>
  461.   Options -Indexes
  462. </IfModule>
  463.  
  464. # Block access to "hidden" directories or files whose names begin with a
  465. # period. This includes directories used by version control systems such as
  466. # Subversion or Git.
  467. #<IfModule mod_rewrite.c>
  468.  # RewriteCond %{SCRIPT_FILENAME} -d [OR]
  469.  # RewriteCond %{SCRIPT_FILENAME} -f
  470.  # RewriteRule "(^|/)\." - [F]
  471. #</IfModule>
  472.  
  473. # Block access to backup and source files. These files may be left by some
  474. # text/html editors and pose a great security danger, when anyone can access
  475. # them.
  476. <FilesMatch "(\.(bak|config|sql|fla|psd|ini|log|sh|inc|swp|dist)|~)$">
  477.   Order allow,deny
  478.   Deny from all
  479.   Satisfy All
  480. </FilesMatch>
  481.  
  482. # If your server is not already configured as such, the following directive
  483. # should be uncommented in order to set PHP's register_globals option to OFF.
  484. # This closes a major security hole that is abused by most XSS (cross-site
  485. # scripting) attacks. For more information: http://php.net/register_globals
  486. #
  487. # IF REGISTER_GLOBALS DIRECTIVE CAUSES 500 INTERNAL SERVER ERRORS:
  488. #
  489. # Your server does not allow PHP directives to be set via .htaccess. In that
  490. # case you must make this change in your php.ini file instead. If you are
  491. # using a commercial web host, contact the administrators for assistance in
  492. # doing this. Not all servers allow local php.ini files, and they should
  493. # include all PHP configurations (not just this one), or you will effectively
  494. # reset everything to PHP defaults. Consult www.php.net for more detailed
  495. # information about setting PHP directives.
  496.  
  497. # php_flag register_globals Off
  498.  
  499. # Rename session cookie to something else, than PHPSESSID
  500. # php_value session.name sid
  501.  
  502. # Disable magic quotes (This feature has been DEPRECATED as of PHP 5.3.0 and REMOVED as of PHP 5.4.0.)
  503. # php_flag magic_quotes_gpc Off
  504.  
  505. # Do not show you are using PHP
  506. # Note: Move this line to php.ini since it won't work in .htaccess
  507. # php_flag expose_php Off
  508.  
  509. # Level of log detail - log all errors
  510. # php_value error_reporting -1
  511.  
  512. # Write errors to log file
  513. # php_flag log_errors On
  514.  
  515. # Do not display errors in browser (production - Off, development - On)
  516. # php_flag display_errors Off
  517.  
  518. # Do not display startup errors (production - Off, development - On)
  519. # php_flag display_startup_errors Off
  520.  
  521. # Format errors in plain text
  522. # Note: Leave this setting 'On' for xdebug's var_dump() output
  523. # php_flag html_errors Off
  524.  
  525. # Show multiple occurrence of error
  526. # php_flag ignore_repeated_errors Off
  527.  
  528. # Show same errors from different sources
  529. # php_flag ignore_repeated_source Off
  530.  
  531. # Size limit for error messages
  532. # php_value log_errors_max_len 1024
  533.  
  534. # Don't precede error with string (doesn't accept empty string, use whitespace if you need)
  535. # php_value error_prepend_string " "
  536.  
  537. # Don't prepend to error (doesn't accept empty string, use whitespace if you need)
  538. # php_value error_append_string " "
  539.  
  540. # Increase cookie security
  541. <IfModule php5_module>
  542.  php_value session.cookie_httponly true
  543. </IfModule>
  544.  
  545.  
  546. ### Vary accept
  547.  
  548. <IfModule mod_headers.c>
  549.  <FilesMatch "\.(js|css|xml|gz)$">
  550.    Header append Vary: Accept-Encoding
  551.  </FilesMatch>
  552. </IfModule>
  553.  
  554.  
  555. RewriteCond %{ENV:REDIRECT_STATUS} 200
  556. RewriteRule .* - [L]
  557.  
  558. #sid
  559.  
  560. RewriteCond %{QUERY_STRING} ^(.*)\&?sid=[a-zA-Z0-9]+\&?(.*)$  
  561. RewriteRule ^(.*) $1?%1%2 [R=301,L]
  562.  
  563. RewriteRule ^(css|js|adminjs_od|admincss|adminjs|file)/.*$ extern.php?g=$1 [QSA,L]
  564.  
  565. RewriteRule \.(js|ico|gif|jpg|png|css|swf|pdf|txt|doc|docx|xls|xml|htc|flv|ttf|woff|eot|svg)$ - [L]
  566.  
  567. RewriteRule ^.*(sitemap\.xml).*$  - [L]
  568.  
  569.  
  570. RewriteCond %{REQUEST_FILENAME} !-f [OR]
  571. RewriteCond %{REQUEST_FILENAME} !-d
  572. RewriteCond %{QUERY_STRING} ^(.*)$
  573. RewriteRule ^(.*)$ index.php [QSA,L]
  574.  
  575.  
  576. #flash
  577. #RewriteRule ^getflash/?$ http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash [NC,L,R=307]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement