andybezbozhny

Apache

Aug 12th, 2012 (edited)
25
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Универсальное решение проблемы постоянных редиректов на домен без www при помощи mod_rewrite.
  2. # Просто и полезно. Работает на любом домене без необходимости править для каждого сайта.
  3. # В корень бросаем файл .htaccess со следующим содержимым:
  4.  
  5. <IfModule mod_rewrite.c>
  6. RewriteEngine On
  7. RewriteBase /
  8. # В переменную окружения %{ENV:PROTOCOL} помещаем протокол
  9. RewriteRule ^(.*)$ - [E=PROTOCOL:http]
  10. RewriteCond %{HTTPS} ^on$ [NC]
  11. RewriteRule ^(.*)$ - [E=PROTOCOL:https]
  12. # Если нужно убираем www
  13. RewriteCond %{SERVER_PORT} ^80$
  14. RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
  15. RewriteRule ^(.*)$ %{ENV:PROTOCOL}://%1%{REQUEST_URI} [R=301,L]
  16. RewriteCond %{HTTP_HOST} ^www\.(.*) [NC]
  17. RewriteRule ^(.*)$ %{ENV:PROTOCOL}://%1:%{SERVER_PORT}%{REQUEST_URI} [R=301,L]
  18. </IfModule>
  19.  
  20. # www.example.net is a valid address, but it redirects all traffic to example.net.
  21.  
  22. RewriteEngine On
  23. RewriteCond %{HTTP_HOST} ^www\.(.+)$ [NC]
  24. RewriteRule ^(.*)$ http://%1/$1 [R=301,L]
  25.  
  26. # temp redirect wordpress content feeds to feedburner
  27. <IfModule mod_rewrite.c>
  28. RewriteEngine on
  29. RewriteCond %{HTTP_USER_AGENT} !FeedBurner [NC]
  30. RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
  31. RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourblog [R=302,NC,L]
  32. </IfModule>
  33.  
  34. # disable hotlinking
  35.  
  36. Options +FollowSymlinks
  37.  
  38. RewriteEngine On
  39. RewriteCond %{HTTP_REFERER} !^$
  40. RewriteCond %{HTTP_REFERER} !^http://(www.)?domainname.com/ [nc]
  41. RewriteRule .*.(gif|jpg|png)$ http://domainname.com/img/stop_stealing_bandwidth.gif[nc]
  42.  
  43. # Сжатие с mod_deflate
  44. # Наряду с Gzip архивированием файлов, вы можете использовать mod_deflate (что предположительно быстрее).
  45. # Поместите указанный код в начало вашего .htaccess файла
  46. # (вы также можете добавить картинки .jpg, .gif, .png, .tiff, .ico).
  47.  
  48. <ifmodule mod_deflate.c="">
  49. <filesmatch .(js|css)$="">
  50. SetOutputFilter DEFLATE
  51. </filesmatch>
  52. </ifmodule>
  53.  
  54. ####### PHP DEBUGGING RULES #######
  55. # supress display of php errors, Below three lines will disable the PHP error reporting to user
  56. php_flag display_startup_errors off
  57. php_flag display_errors off
  58. php_flag html_errors off
  59.  
  60. # enable verbose PHP error logging to a file, Below three lines will log the all PHP error, warning and notices in log files at the path specified.
  61. php_flag  log_errors on
  62. php_value error_reporting 2047
  63. php_value error_log  /home/domain.com/php.error.log
  64. ####### END PHP DEBUGGING RULES #######
  65.  
  66. #Увеличиваем максимальный размер загружаемого файла
  67. php_value upload_max_filesize 100M
  68. #Увеличиваем максимальный размер файла передаваемого пост-запросом
  69. php_value post_max_size 100M
  70. #Увеличиваем время выполнения скрипта
  71. php_value max_execution_time 700
  72.  
  73. # Redirect HTTP tO HTTPS
  74.  
  75. RewriteEngine On
  76. RewriteCond %{HTTPS} off
  77. RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
  78.  
  79. # Сжатие текстовых файлов
  80.  
  81. AddOutputFilterByType DEFLATE text/plain
  82. AddOutputFilterByType DEFLATE text/html
  83. AddOutputFilterByType DEFLATE text/xml
  84. AddOutputFilterByType DEFLATE text/css
  85. AddOutputFilterByType DEFLATE application/xml
  86. AddOutputFilterByType DEFLATE application/xhtml+xml
  87. AddOutputFilterByType DEFLATE application/rss+xml
  88. AddOutputFilterByType DEFLATE application/javascript
  89. AddOutputFilterByType DEFLATE application/x-javascript
  90.  
  91. <IfModule mod_gzip.c>
  92. mod_gzip_on Yes
  93. mod_gzip_dechunk Yes
  94. mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  95. mod_gzip_item_include handler ^cgi-script$
  96. mod_gzip_item_include mime ^text\.*
  97. mod_gzip_item_include mime ^application/x-javascript.*
  98. mod_gzip_item_exclude mime ^image\.*
  99. mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  100. </IfModule>
  101.  
  102. # Обход диалога загрузки
  103. AddType application/octet-stream .pdf
  104. AddType application/octet-stream .zip
  105. AddType application/octet-stream .mp3
  106.  
  107. # Кэширование файлов
  108. <FilesMatch ".(flv|gif|jpg|jpeg|png|ico|swf|js|css|pdf)$">
  109. Header set Cache-Control "max-age=2592000"
  110. </FilesMatch>
  111.  
  112. # удаление слэша на конце URL
  113. RewriteEngine On
  114. RewriteBase /
  115. RewriteCond %{HTTP_HOST} (.*)
  116. RewriteCond %{REQUEST_URI} /$ [NC]
  117. RewriteRule ^(.*)(/)$ $1 [L,R=301]
  118.  
  119. # добавление слэша в конец URL
  120. RewriteEngine On
  121. RewriteBase /
  122. RewriteCond %{REQUEST_FILENAME} !-f
  123. RewriteCond %{REQUEST_URI} !(.*)/$
  124. RewriteRule ^(.*[^/])$ $1/ [L,R=301]
  125.  
  126. # CORSifying
  127. <IfModule mod_headers.c>
  128. Header add Access-Control-Allow-Origin "*"
  129. Header add Access-Control-Allow-Methods "PUT, GET, POST, DELETE, OPTIONS"
  130. Header set Access-Control-Allow-Headers "Content-Type, Authorization"
  131. </IfModule>
Advertisement
Add Comment
Please, Sign In to add comment