Posted By

Eloi on 05/11/09


Tagged

modrewrite htaccess apache


Versions (?)

Who likes this?

12 people have marked this snippet as a favorite

brent-man
Eloi
ikimozu
heinz1959
smart1
kernelpanics
profpatsy
vkolev
NyX
JulienBreux
Kurt
wirenaught


Mod Rewrite


 / Published in: Apache
 

  1. #Redirecting to lowercase
  2.  
  3. RewriteMap lc int:tolower
  4. RewriteCond %{REQUEST_URI} [A-Z]
  5. RewriteRule (.*) ${lc:$1} [R=301,L]
  6.  
  7.  
  8. #This rule is perfect to redirecting the hundreds of daily requests for misplaced robots.txt files such as the following:
  9. # http://dominio.com/foo/robots.txt
  10. # http://dominio.com/foo/bar/robots.txt
  11. # http://dominio.com/foo/2009/05/09/robots.txt
  12. # http://dominio.com/foo/bar/xyz/robots.txt
  13.  
  14. RedirectMatch 301 robots\.txt http://dominio.com/robots.txt
  15.  
  16.  
  17. #Redirect favicon.ico & favicon.gif
  18.  
  19. RedirectMatch 301 favicon\.ico http://perishablepress.com/favicon.ico
  20. RedirectMatch 301 favicon\.gif http://perishablepress.com/favicon.ico
  21.  
  22.  
  23. #Error 404
  24.  
  25. ErrorDocument 404 errors/404.html
  26.  
  27.  
  28. #Environment Variables
  29.  
  30. SetEnv APPLICATION_ENV development
  31.  
  32. #Cache
  33.  
  34. #1 Year
  35. <FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|swf|mp3|mp4)$">
  36. Header set Cache-Control "public"
  37. Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
  38. Header unset Last-Modified
  39. </FilesMatch>
  40.  
  41. #2 Hours
  42. <FilesMatch "\.(html|htm|xml|txt|xsl)$">
  43. Header set Cache-Control "max-age=7200, must-revalidate"
  44. </FilesMatch>
  45.  
  46. <FilesMatch "\.(js|css)$">
  47. SetOutputFilter DEFLATE
  48. Header set Expires "Thu, 15 Apr 2010 20:00:00 GMT"
  49. </FilesMatch>
  50.  
  51.  
  52. #Compress output using GZIP
  53.  
  54. <IfModule mod_gzip.c>
  55. mod_gzip_on Yes
  56. mod_gzip_dechunk Yes
  57. mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  58. mod_gzip_item_include handler ^cgi-script$
  59. mod_gzip_item_include mime ^text/.*
  60. mod_gzip_item_include mime ^application/x-javascript.*
  61. mod_gzip_item_exclude mime ^image/.*
  62. mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
  63. </IfModule>
  64.  
  65.  
  66. #Redirecting non www URL to www URL
  67.  
  68. RewriteEngine On
  69. RewriteCond %{HTTP_HOST} ^viralpatel\.net$
  70. RewriteRule (.*) http://www.viralpatel.net/$1 [R=301,L]
  71.  
  72.  
  73. #Change Charset and Language headers
  74.  
  75. AddDefaultCharset UTF-8
  76. DefaultLanguage ens-ES
  77.  
  78.  
  79. #Send Custom Headers
  80.  
  81. Header set X-Pingback "http://www.askapache.com/xmlrpc.php"
  82. Header set Content-Language "es-ES"

Report this snippet  

You need to login to post a comment.