pastebin

Paste Search Dynamic
Recent pastes
Popular .htaccess Examples
  1. # htaccess custom error pages
  2. ErrorDocument 400 /errors/400.html
  3. ErrorDocument 401 /errors/401.html
  4. ErrorDocument 403 /errors/403.html
  5. ErrorDocument 404 /errors/404.html
  6. ErrorDocument 500 /errors/500.html
  7. #Redirect to an external URL
  8. # htaccess custom error redirects
  9. ErrorDocument 400 http://yourdomain.tld/400_information.html
  10. ErrorDocument 401 http://yourdomain.tld/401_information.html
  11. ErrorDocument 403 http://yourdomain.tld/403_information.html
  12. ErrorDocument 404 http://yourdomain.tld/404_information.html
  13. ErrorDocument 500 http://yourdomain.tld/500_information.html
  14. # htaccess custom error scripts
  15. ErrorDocument 400 /errors/redirection.php
  16. ErrorDocument 401 /errors/authentication.php
  17. ErrorDocument 403 /errors/explanation.php
  18. ErrorDocument 404 /cgi-bin/not_found.pl
  19. ErrorDocument 500 /cgi-bin/server_error.pl
  20. #Password Protection With .htaccess
  21. #Create .htpasswd file with your desired username and password in any text editor (like Notepad)
  22.  #Protect single file
  23. <Files admin.php>
  24. AuthName "Dialog prompt"
  25. AuthType Basic
  26. AuthUserFile /home/username/example.com/.htpasswd
  27. Require valid-user
  28. </Files>
  29. #Protect multiple files
  30. <FilesMatch "^(admin|root).php$">
  31. AuthName "Dialog prompt"
  32. AuthType Basic
  33. AuthUserFile /home/username/example.com/.htpasswd
  34. Require valid-user
  35. </FilesMatch>
  36. #Blacklisting by IP
  37. order allow,deny
  38. deny from 110.20.4.3
  39. deny from 189.36.5.2
  40. allow from all
  41. #Setting Multiple Default Pages
  42. DirectoryIndex index.php index.shtml index.html
  43. #Basic Page Redirect
  44. Redirect 301 /blog.cgi http://blog.example.com
  45. #Redirecting an entire site
  46. Redirect 301 / http://mynewurl.com
  47. #Redirecting www to non-www
  48. Options +FollowSymlinks
  49. RewriteEngine on
  50. RewriteCond % ^www.example.com [NC]
  51. RewriteRule ^(.*)$ http://example.org/$1 [R=301,NC]
  52. #MIME types on your server
  53. AddType image/jpeg jpeg jpg jpe JPG
  54. #Force Download by MIME Type
  55. AddType application/octet-stream pdf
  56. AddType application/octet-stream pdf doc docx rtf
  57. #List of File Extensions and MIME Types
  58.  
  59. AddType application/macbinhex-40 hqx
  60. AddType application/netalive net
  61. AddType application/netalivelink nel
  62. AddType application/octet-stream bin exe
  63. AddType application/oda oda
  64. AddType application/pdf pdf
  65. AddType application/postscript ai eps ps
  66. AddType application/rtf rtf
  67. AddType application/x-bcpio bcpio
  68. AddType application/x-cpio cpio
  69. AddType application/x-csh csh
  70. AddType application/x-director dcr
  71. AddType application/x-director dir
  72. AddType application/x-director dxr
  73. AddType application/x-dvi dvi
  74. AddType application/x-gtar gtar
  75. AddType application/x-hdf hdf
  76. AddType application/x-httpd-cgi cgi
  77. AddType application/x-latex latex
  78. AddType application/x-mif mif
  79. AddType application/x-netcdf nc cdf
  80. AddType application/x-onlive sds
  81. AddType application/x-sh sh
  82. AddType application/x-shar shar
  83. AddType application/x-sv4cpio sv4cpio
  84. AddType application/x-sv4crc sv4crc
  85. AddType application/x-tar tar
  86. AddType application/x-tcl tcl
  87. AddType application/x-tex tex
  88. AddType application/x-texinfo texinfo texi
  89. AddType application/x-troff t tr roff
  90. AddType application/x-troff-man man
  91. AddType application/x-troff-me me
  92. AddType application/x-troff-ms ms
  93. AddType application/x-ustar ustar
  94. AddType application/x-wais-source src
  95. AddType application/zip zip
  96. AddType audio/basic au snd
  97. AddType audio/x-aiff aif aiff aifc
  98. AddType audio/x-midi mid
  99. AddType audio/x-pn-realaudio ram
  100. AddType audio/x-wav wav
  101. AddType image/gif gif GIF
  102. AddType image/ief ief
  103. AddType image/jpeg jpeg jpg jpe JPG
  104. AddType image/tiff tiff tif
  105. AddType image/x-cmu-raster ras
  106. AddType image/x-portable-anymap pnm
  107. AddType image/x-portable-bitmap pbm
  108. AddType image/x-portable-graymap pgm
  109. AddType image/x-portable-pixmap ppm
  110. AddType image/x-rgb rgb
  111. AddType image/x-xbitmap xbm
  112. AddType image/x-xpixmap xpm
  113. AddType image/x-xwindowdump xwd
  114. AddType text/html html htm
  115. AddType text/plain txt
  116. AddType text/richtext rtx
  117. AddType text/tab-separated-values tsv
  118. AddType text/x-server-parsed-html shtml sht
  119. AddType text/x-setext etx
  120. AddType video/mpeg mpeg mpg mpe
  121. AddType video/quicktime qt mov
  122. AddType video/x-msvideo avi
  123. AddType video/x-sgi-movie movie
  124. AddType x-world/x-vrml wrl
  125. #Block Hotlinking
  126. #Hotlinking is the practice of linking to resources from other domains instead of uploading the content to your own server and serving it yourself.
  127. RewriteEngine on
  128. RewriteCond % !^$
  129. RewriteCond % !^http://(www.)?example.com/.*$ [NC]
  130. RewriteRule .(gif|jpg|jpeg|png|js|css)$ - [F]
  131. #Serving up Alternative Content
  132. #Instead of failing the request, you simply redirect it to the “special” image:
  133. RewriteEngine on
  134. RewriteCond % !^$
  135. RewriteCond % !^http://(www.)?example.com/.*$ [NC]
  136. RewriteRule .(gif|jpg)$ http://www.example.com/no-hotlinking.jpg [R,L]
  137. #Disable or Enable Index
  138. #Disabling Indexes
  139. Options -Indexes
  140. #Enabling Indexes
  141. Options +Indexes
  142. #Hiding some files from the Index
  143. IndexIgnore *.gif *.jpg *.cgi *.log
  144. #Enabling CGI Everywhere
  145. AddHandler cgi-script .cgi
  146. Options +ExecCGI
  147. #Optimize Website Using .Htaccess File
  148. #Utilize Caching
  149. # BEGIN EXPIRES
  150. <IfModule mod_expires.c>
  151. ExpiresActive On
  152. ExpiresDefault "access plus 10 days"
  153. ExpiresByType text/css "access plus 1 week"
  154. ExpiresByType text/plain "access plus 1 month"
  155. ExpiresByType image/gif "access plus 1 month"
  156. ExpiresByType image/png "access plus 1 month"
  157. ExpiresByType image/jpeg "access plus 1 month"
  158. ExpiresByType application/x-javascript "access plus 1 month"
  159. ExpiresByType application/javascript "access plus 1 week"
  160. ExpiresByType application/x-icon "access plus 1 year"
  161. </IfModule>
  162. # END EXPIRES
  163. #Compress Content Using Mod Deflate
  164. # COMPRESSION
  165. # BEGIN DEFLATE COMPRESSION
  166. <IfModule mod_deflate.c>
  167. # Compress HTML, CSS, JavaScript, Text, XML and fonts
  168. AddOutputFilterByType DEFLATE application/javascript
  169. AddOutputFilterByType DEFLATE application/rss+xml
  170. AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
  171. AddOutputFilterByType DEFLATE application/x-font
  172. AddOutputFilterByType DEFLATE application/x-font-opentype
  173. AddOutputFilterByType DEFLATE application/x-font-otf
  174. AddOutputFilterByType DEFLATE application/x-font-truetype
  175. AddOutputFilterByType DEFLATE application/x-font-ttf
  176. AddOutputFilterByType DEFLATE application/x-javascript
  177. AddOutputFilterByType DEFLATE application/xhtml+xml
  178. AddOutputFilterByType DEFLATE application/xml
  179. AddOutputFilterByType DEFLATE font/opentype
  180. AddOutputFilterByType DEFLATE font/otf
  181. AddOutputFilterByType DEFLATE font/ttf
  182. AddOutputFilterByType DEFLATE image/svg+xml
  183. AddOutputFilterByType DEFLATE image/x-icon
  184. AddOutputFilterByType DEFLATE text/css
  185. AddOutputFilterByType DEFLATE text/html
  186. AddOutputFilterByType DEFLATE text/javascript
  187. AddOutputFilterByType DEFLATE text/plain
  188. AddOutputFilterByType DEFLATE text/xml
  189. </IfModule>
  190. # END DEFLATE COMPRESSION
  191. # END COMPRESSION
  192. #Gzip Compression
  193. # BEGIN GZIP
  194. # BEGIN GZIP COMPRESSION
  195. <IfModule mod_gzip.c>
  196. mod_gzip_on Yes
  197. mod_gzip_dechunk Yes
  198. mod_gzip_item_include file .(html?|txt|css|js|php|pl)$
  199. mod_gzip_item_include handler ^cgi-script$
  200. mod_gzip_item_include mime ^text/.*
  201. mod_gzip_item_include mime ^application/x-javascript.*
  202. mod_gzip_item_exclude mime ^image/.*
  203. mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  204. </IfModule>
  205. # END GZIP COMPRESSION
  206. # END GZIP
  207. #Caching
  208. #CACHE CONTROL
  209. # BEGIN Cache-Control Headers
  210. <ifModule mod_headers.c>
  211. <filesMatch ".(ico|jpe?g|png|gif|swf)$">
  212. Header set Cache-Control "public"
  213. </filesMatch>
  214. <filesMatch ".(css)$">
  215. Header set Cache-Control "public"
  216. </filesMatch>
  217. <filesMatch ".(js)$">
  218. Header set Cache-Control "private"
  219. </filesMatch>
  220. <filesMatch ".(x?html?|php)$">
  221. Header set Cache-Control "private, must-revalidate"
  222. </filesMatch>
  223. </ifModule>
  224. # END Cache-Control Headers
  225. #END CACHE CONTROL
  226. # FORCE TRAILING SLASH
  227. <IfModule mod_rewrite.c>
  228. RewriteCond %{REQUEST_URI} /+[^.]+$
  229. RewriteRule ^(.+[^/])$ %{REQUEST_URI}/ [R=301,L]
  230. </IfModule>
  231. # END FORCE TRAILING SLASH
  232. # PREVENT HOTLINKING
  233. RewriteEngine On
  234. #Replace ?yourdomainname.com/ with your website url
  235. RewriteCond %{HTTP_REFERER} !^http://(.+.)?yourdomainname.com/ [NC]
  236. RewriteCond %{HTTP_REFERER} !^$
  237. #Replace /images/nohotlink.jpg with your "hotlinking is not permitted" image url
  238. RewriteRule .*.(jpe?g|gif|bmp|png)$ /hotlinksnotpermitted.jpg [L]
  239. # END PREVENT HOTLINKING
  240. #Redirect Website Visitors To A Mobile Site:
  241. # REDIRECT MOBILE DEVICES
  242. RewriteEngine On
  243. RewriteCond %{REQUEST_URI} !^/m/.*$
  244. RewriteCond %{HTTP_ACCEPT} "text/vnd.wap.wml|application/vnd.wap.xhtml+xml" [NC,OR]
  245. RewriteCond %{HTTP_USER_AGENT} "acs|alav|alca|amoi|audi|aste|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-" [NC,OR]
  246. RewriteCond %{HTTP_USER_AGENT} "dang|doco|eric|hipt|inno|ipaq|java|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-" [NC,OR]
  247. RewriteCond %{HTTP_USER_AGENT} "maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|opwv" [NC,OR]
  248. RewriteCond %{HTTP_USER_AGENT} "palm|pana|pant|pdxg|phil|play|pluc|port|prox|qtek|qwap|sage|sams|sany" [NC,OR]
  249. RewriteCond %{HTTP_USER_AGENT} "sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo" [NC,OR]
  250. RewriteCond %{HTTP_USER_AGENT} "teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|w3cs|wap-|wapa|wapi" [NC,OR]
  251. RewriteCond %{HTTP_USER_AGENT} "wapp|wapr|webc|winw|winw|xda|xda-" [NC,OR]
  252. RewriteCond %{HTTP_USER_AGENT} "up.browser|up.link|windowssce|iemobile|mini|mmp" [NC,OR]
  253. RewriteCond %{HTTP_USER_AGENT} "symbian|midp|wap|phone|pocket|mobile|pda|psp" [NC]
  254. #------------- The line below excludes the iPad
  255. RewriteCond %{HTTP_USER_AGENT} !^.*iPad.*$
  256. #-------------
  257. RewriteCond %{HTTP_USER_AGENT} !macintosh [NC] #*SEE NOTE BELOW
  258. RewriteRule ^(.*)$ /m/ [L,R=302]
  259. # END REDIRECT MOBILE DEVICES
  260. # STOP SPAM ON WORDPRESS BLOG
  261. RewriteEngine On
  262. RewriteCond %{REQUEST_METHOD} POST
  263. RewriteCond %{REQUEST_URI} .wp-comments-post.php*
  264. RewriteCond %{HTTP_REFERER} !.*yourdomainname.* [OR]
  265. RewriteCond %{HTTP_USER_AGENT} ^$
  266. RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]
  267. </IfModule>
  268. # END STOP SPAM ON WORDPRESS BLOG
  269. #Redirect Feeds
  270. # REDIRECT DIFFERENT FEEDS TO A SINGLE FORMAT
  271. <IfModule mod_alias.c>
  272. RedirectMatch 301 /feed/(atom|rdf|rss|rss2)/?$ http://yourdomainname.com/feed/
  273. RedirectMatch 301 /comments/feed/(atom|rdf|rss|rss2)/?$ http://yourdomainname.com/comments/feed/
  274. </IfModule>
  275. # END REDIRECT DIFFERENT FEEDS TO A SINGLE FORMAT
  276. #Configure Your Website For HTML5 Videos
  277. # CONFIGURE YOUR WEBSITE FOR HTML5 VIDEOS
  278. RewriteCond %{REQUEST_FILENAME} !-f
  279. RewriteCond %{REQUEST_FILENAME} !-d
  280. RewriteCond %{REQUEST_URI} !=/favicon.ico
  281. AddType video/ogg .ogv
  282. AddType video/ogg .ogg
  283. AddType video/mp4 .mp4
  284. AddType video/webm .webm
  285. AddType application/x-shockwave-flash swf
  286. # END CONFIGURE YOUR WEBSITE FOR HTML5 VIDEOS
  287. #Log PHP Errors Into An Error Log
  288. # LOG PHP errors INTO ~/public_html/php_error.log
  289. # display no errs to user
  290. php_flag display_startup_errors off
  291. php_flag display_errors off
  292. php_flag html_errors off
  293. # log to file
  294. php_flag log_errors on
  295. php_value error_log ~/public_html/php_error.log
  296. # END LOG PHP errors INTO ~/public_html/php_error.log
  297. # RUN PHP INSIDE JAVASCRIPT FILES
  298. AddType application/x-httpd-php .js
  299. AddHandler x-httpd-php5 .js
  300. <FilesMatch ".(js|php)$">
  301. SetHandler application/x-httpd-php
  302. </FilesMatch>
  303. # RUN PHP INSIDE JAVASCRIPT FILES
  304. #Redirect Website To Https
  305. #Force SSL without www
  306. RewriteEngine On
  307. RewriteCond %{SERVER_PORT} 80
  308. RewriteRule ^(.*)$ https://yourdomain.tld/$1 [R,L]
  309. #Force SSL with www
  310. RewriteCond %{SERVER_PORT} 80
  311. RewriteRule ^(.*)$ https://www.yourdomain.tld/$1 [R,L]
  312.  
  313.  
  314.  
  315.  
  316.  
  317.  
  318.  
  319.  
Parsed in 0.029 seconds