Posted By

erik on 03/04/09


Tagged

htaccess apache cache htpasswd


Versions (?)

Who likes this?

3 people have marked this snippet as a favorite

Bluewall
xtheonex
jamesming


htaccess file sample


 / Published in: Apache
 

URL: http://www.askapache.com/htaccess/apache-authentication-in-htaccess.html

  1. #
  2. # DEFAULT SETTINGS
  3. #
  4. Options ExecCGI -Indexes
  5. DirectoryIndex index.php index.html index.htm
  6.  
  7. ErrorDocument 400 /cgi-bin/error.php
  8. ErrorDocument 401 /cgi-bin/error.php
  9. ErrorDocument 403 /cgi-bin/forbidden.cgi
  10. ErrorDocument 404 /404.html
  11. ErrorDocument 405 /cgi-bin/error.php
  12. ErrorDocument 406 /cgi-bin/error.php
  13. ErrorDocument 409 /cgi-bin/error.php
  14. ErrorDocument 413 /cgi-bin/error.php
  15. ErrorDocument 414 /cgi-bin/error.php
  16. ErrorDocument 500 /cgi-bin/error.php
  17. ErrorDocument 501 /cgi-bin/error.php
  18.  
  19. ### DEFAULTS
  20. ServerSignature Off
  21.  
  22. AddType video/x-flv .flv
  23. AddType application/x-shockwave-flash .swf
  24. AddType image/x-icon .ico
  25.  
  26. AddDefaultCharset UTF-8
  27. AddLanguage en-US .html .htm .txt .xml .php
  28.  
  29. SetEnv TZ America/Indianapolis
  30. SetEnv SERVER_ADMIN [email protected]
  31.  
  32. ### PHPINI-CGI
  33. #AddHandler php-cgi .php
  34. #Action php-cgi /cgi-bin/php5.cgi
  35.  
  36. ### FAST-CGI
  37. #AddHandler fastcgi-script .fcg .fcgi .fpl
  38. #AddHandler php5-fastcgi .php
  39. #Action php5-fastcgi /cgi-bin/fastcgi.fcgi
  40.  
  41. #
  42. # HEADERS and CACHING
  43. #
  44. # 1 YEAR
  45. <FilesMatch "\.(flv|ico|pdf)$">
  46. Header set Cache-Control "max-age=29030400, public"
  47. </FilesMatch>
  48.  
  49. # 1 WEEK
  50. <FilesMatch "\.(jpg|jpeg|png|gif|swf)$">
  51. Header set Cache-Control "max-age=604800, public"
  52. </FilesMatch>
  53.  
  54. # 3 HOUR
  55. <FilesMatch "\.(txt|xml|js|css)$">
  56. Header set Cache-Control "max-age=10800"
  57. </FilesMatch>
  58.  
  59. # 1 MIN
  60. <FilesMatch "\.(html|htm|php)$">
  61. Header set Cache-Control "max-age=0, private, no-store, no-cache, must-revalidate"
  62. Header set P3P "policyref=\"/w3c/p3p.xml\", CP=\"NOI DSP COR NID CUR ADM DEV OUR BUS\""
  63. Header set imagetoolbar "no"
  64. </FilesMatch>
  65.  
  66. #
  67. # REWRITES AND REDIRECTS
  68. #
  69. ### SEO REDIRECTS
  70. #Redirect 301 /ssl-ns.html /2006/htaccess/apache-ssl-in-htaccess-examples.html
  71. #Redirect 301 /ht.tml
  72. #Redirect 301 /index.html /
  73. #RedirectMatch 301 /2006/htaccess-forum/(.*) /2006/htaccess/$1
  74. #RedirectMatch 301 /(.*)rfc2616(.*) http://rfc.askapache.com/rfc2616/rfc2616.html
  75. #RedirectMatch 301 /phpmanual(.*) /manual/en/$1
  76.  
  77. ### REWRITES
  78. RewriteEngine On
  79. RewriteBase /
  80.  
  81. ### WORDPRESS
  82. #<IfModule mod_rewrite.c>
  83. #RewriteEngine On
  84. #RewriteBase /
  85. #RewriteCond %{REQUEST_FILENAME} !-f
  86. #RewriteCond %{REQUEST_FILENAME} !-d
  87. #RewriteRule . /index.php [L]
  88. #</IfModule>
  89.  
  90. ### REQUIRE WWW
  91. #RewriteCond %{HTTP_HOST} !^www\.askapache\.com$ [NC]
  92. #RewriteRule ^(.*)$ /$1 [R=301,L]
  93.  
  94. ### STOP LOOP CODE
  95. #RewriteCond %{ENV:REDIRECT_STATUS} 200
  96. #RewriteRule ^.*$ - [L]
  97.  
  98. ### REDIRECT BLOG FEED TO FEEDBURNER
  99. #RewriteCond %{HTTP_USER_AGENT} !^.*(FeedBurner|FeedValidator|Recent) [NC]
  100. #RewriteRule ^feed/?.*$ http://feeds.feedburner.com/apache/htaccess [L,R=302]
  101.  
  102. ### BLOCK WGET
  103. #RewriteCond %{HTTP_USER_AGENT} ^Wget.* [NC]
  104. #RewriteRule .* /cgi-bin/forbidden.cgi [L]
  105.  
  106. #
  107. # AUTHENTICATION
  108. #
  109. ### BASIC PASSWORD PROTECTION
  110. #AuthName "Prompt"
  111. #AuthUserFile /home/askapache.com/.htpasswd
  112. #AuthType basic
  113. #Require valid-user
  114.  
  115. ### UNDER CONSTRUCTION PROTECTION
  116. #AuthName "Under Development"
  117. #AuthUserFile /home/askapache.com/.htpasswd
  118. #AuthType basic
  119. #Require valid-user
  120. #Order Deny,Allow
  121. #Deny from all
  122. #Allow from 23.23.23.1 w3.org googlebot.com google.com google-analytics.com
  123. #Satisfy Any

Report this snippet  

You need to login to post a comment.