Printable Version of Topic

Click here to view this topic in its original format

Web Design Seo Forum _ Htaccess Guides _ Htaccess Code To Speed Up Joomla

Posted by: Web Design Seo Jun 11 2012, 06:42 AM

How-to make my Wordpress or Joomla fast? How to have really fast Joomla 3 and to Speed Up my Joomla website?

Here is some example code for Htaccess to speed up your joomla. Use this code in your .htaccess:

Код
########## Begin - Joomla! core SEF Section
#
RewriteCond %{HTTP_USER_AGENT} !^.*(2.0\ MMP|240x320|400X240|AvantGo|BlackBerry|Blazer|Cellphone|Danger|DoCoMo|Elaine/3.0|EudoraWeb|Googlebot-Mobile|hiptop|IEMobile|KYOCERA/WX310K|LG/U990|MIDP-2.|MMEF20|MOT-V|NetFront|Newt|Nintendo\ Wii|Nitro|Nokia|Opera\ Mini|Palm|PlayStation\ Portable|portalmmm|Proxinet|ProxiNet|SHARP-TQ-GX10|SHG-i900|Small|SonyEricsson|Symbian\ OS|SymbianOS|TS21i-10|UP.Browser|UP.Link|webOS|Windows\ CE|WinWAP|YahooSeeker/M1A1-R2D2|iPhone|iPod|Android|BlackBerry9530|LG-TU915\ Obigo|LGE\ VX|webOS|Nokia5800).* [NC]
RewriteCond %{HTTP_user_agent} !^(w3c\ |w3c-|acs-|alav|alca|amoi|audi|avan|benq|bird|blac|blaz|brew|cell|cldc|cmd-|dang|doco|eric|hipt|htc_|inno|ipaq|ipod|jigs|kddi|keji|leno|lg-c|lg-d|lg-g|lge-|lg/u|maui|maxo|midp|mits|mmef|mobi|mot-|moto|mwbp|nec-|newt|noki|palm|pana|pant|phil|play|port|prox|qwap|sage|sams|sany|sch-|sec-|send|seri|sgh-|shar|sie-|siem|smal|smar|sony|sph-|symb|t-mo|teli|tim-|tosh|tsm-|upg1|upsi|vk-v|voda|wap-|wapa|wapi|wapp|wapr|webc|winw|winw|xda\ |xda-).* [NC]
RewriteCond %{HTTP:Accept-Encoding} gzip
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteCond %{REQUEST_URI} !^/index.php
RewriteCond %{REQUEST_URI} (/|\.php|\.html|\.htm|\.feed|\.pdf|\.raw|/[^.]*)$  [NC]
RewriteRule (.*) index.php
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization},L]
#
########## End - Joomla! core SEF Section

<IfModule mod_deflate.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
</IfModule>


If you use this code for Htaccess, your joomla will run faster and will load minimal your server.

Posted by: Web Design Seo Jun 11 2012, 07:27 AM

Or directly use exact htaccess for Joomla 1.5:

Код
Options -Indexes
RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files

# Block out any script trying to set a mosConfig value through the URL
RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode data within the URL
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
########## End - Rewrite rules to block out some common exploits

#optional rewrite www to non-www
#RewriteCond %{HTTP_HOST} ^my-joomla-site.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www.my-joomla-site.com$
#RewriteRule (.*) http://my-joomla-site.com/$1 [R=301,L]
#optional rewrite www to non-www

#optional error messages and redirect of error pages
#ErrorDocument 403 "My text form My Joomla! site: Sorry! Access denied!"
#ErrorDocument 404 http://my-joomla-site.com/
#ErrorDocument 500 http://my-joomla-site.com/
#optional error messages and redirect of error pages

########## Begin - Joomla! core SEF Section
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} (/[^.]*|\.(php|html?|feed|pdf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
########## End - Joomla! core SEF Section

<IfModule mod_deflate.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
</IfModule>


Note that you need to edit your custom error message:
Цитат
My text form My Joomla! site: Sorry! Access denied!

and url of your joomla install:
Код
my-joomla-site.com

Posted by: Web Design Seo Jun 11 2012, 07:37 AM

Or directly use this htaccess for Joomla 2.5:

Код
Options -Indexes
RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
## This attempts to block the most common type of exploit `attempts` to Joomla!
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
#Order allow,deny
#Deny from all
#Satisfy all
#</Files>
## End of deny access to extension xml files

## Begin - Rewrite rules to block out some common exploits.
# Block out any script trying to base64_encode data within the URL.
RewriteCond %{QUERY_STRING} base64_encode[^(]*\([^)]*\) [OR]
# Block out any script that includes a <script> tag in URL.
RewriteCond %{QUERY_STRING} (<|%3C)([^s]*s)+cript.*(>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL.
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL.
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Return 403 Forbidden header and show the content of the root homepage
RewriteRule .* index.php [F]
## End - Rewrite rules to block out some common exploits.

#optional rewrite www to non-www
#RewriteCond %{HTTP_HOST} ^my-joomla-site.com$ [OR]
#RewriteCond %{HTTP_HOST} ^www.my-joomla-site.com$
#RewriteRule (.*) http://my-joomla-site.com/$1 [R=301,L]
#optional rewrite www to non-www

#optional error messages and redirect of error pages
#ErrorDocument 403 "My text form My Joomla! site: Sorry! Access denied!"
#ErrorDocument 404 http://my-joomla-site.com/
#ErrorDocument 500 http://my-joomla-site.com/
#optional error messages and redirect of error pages

## Begin - Joomla! core SEF Section.
#
RewriteRule .* - [E=HTTP_AUTHORIZATION:%{HTTP:Authorization}]
#
# If the requested path and file is not /index.php and the request
# has not already been internally rewritten to the index.php script
RewriteCond %{REQUEST_URI} !^/index\.php
# and the request is for something within the component folder,
# or for the site root, or for an extensionless URL, or the
# requested URL ends with one of the listed extensions
RewriteCond %{REQUEST_URI} /component/|(/[^.]*|\.(php|html?|feed|pdf|vcf|raw))$ [NC]
# and the requested path and file doesn't directly match a physical file
RewriteCond %{REQUEST_FILENAME} !-f
# and the requested path and file doesn't directly match a physical folder
RewriteCond %{REQUEST_FILENAME} !-d
# internally rewrite the request to the index.php script
RewriteRule .* index.php [L]
#
## End - Joomla! core SEF Section.

<IfModule mod_deflate.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault A600
ExpiresByType image/x-icon A2592000
ExpiresByType application/x-javascript A604800
ExpiresByType text/css A604800
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/jpeg A2592000
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash A2592000
ExpiresByType video/x-flv A2592000
ExpiresByType application/pdf A2592000
ExpiresByType text/html A600
</IfModule>


Note that you need to edit your custom error message:
Цитат
My text form My Joomla! site: Sorry! Access denied!

and url of your joomla install:
Код
my-joomla-site.com

Posted by: Web Design Seo Jun 11 2012, 11:55 AM

You can find here, in the same category http://3dwebdesign.org/forum/htaccess-guides-f12.

Posted by: Web Design Seo Sep 25 2015, 04:00 PM

Latest version for Joomla 3 (add code at end of your .htaccess file):

Код
<IfModule mod_deflate.c>
<FilesMatch "\.(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
#Compress HTML, CSS, JavaScript, Text, XML and fonts
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-woff
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
#Remove browser bugs (only needed for really old browsers)
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/x-icon "access plus 12 month"
ExpiresByType application/x-font-woff "access plus 12 month"
ExpiresByType image/icon "access plus 12 month"
ExpiresByType application/x-javascript "access plus 2 month"
ExpiresByType text/javascript "access plus 2 month"
ExpiresByType text/css "access plus 2 month"
ExpiresByType image/gif "access plus 2 month"
ExpiresByType image/png "access plus 2 month"
ExpiresByType image/bmp "access plus 2 month"
ExpiresByType image/jpeg "access plus 2 month"
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash "access plus 2 month"
ExpiresByType video/x-flv "access plus 2 month"
ExpiresByType application/pdf "access plus 2 month"
ExpiresByType text/html A6000
</IfModule>

<IfModule mod_headers.c>
<FilesMatch "\.(ico|pdf|flv|swf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

# Set Keep Alive Header
<IfModule mod_headers.c>
    Header set Connection keep-alive
</IfModule>

Posted by: Web Design Seo Feb 15 2017, 08:18 AM

Code works with any Joomla version, Wordpress, OpenCart and any other CMS! Add code at end of your .htaccess file.

Latest version (Added popular fonts to mod_deflate and mod_headers):

Код
<IfModule mod_deflate.c>
<FilesMatch "\.(ttf|otf|eot|woff|svg|ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)(\.gz)?$">
SetOutputFilter DEFLATE
Header set Expires "max-age=29030400, public"
Header unset ETag
FileETag None
</FilesMatch>
</IfModule>

<IfModule mod_deflate.c>
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/vnd.ms-fontobject
AddOutputFilterByType DEFLATE application/x-font
AddOutputFilterByType DEFLATE application/x-font-opentype
AddOutputFilterByType DEFLATE application/x-font-otf
AddOutputFilterByType DEFLATE application/x-font-truetype
AddOutputFilterByType DEFLATE application/x-font-ttf
AddOutputFilterByType DEFLATE application/x-font-woff
AddOutputFilterByType DEFLATE application/x-javascript
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE font/opentype
AddOutputFilterByType DEFLATE font/otf
AddOutputFilterByType DEFLATE font/ttf
AddOutputFilterByType DEFLATE image/svg+xml
AddOutputFilterByType DEFLATE image/x-icon
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/javascript
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/xml
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4\.0[678] no-gzip
BrowserMatch \bMSIE !no-gzip !gzip-only-text/html
Header append Vary User-Agent
</IfModule>

<IfModule mod_expires.c>
ExpiresActive On
ExpiresDefault "access plus 1 week"
ExpiresByType image/x-icon "access plus 12 month"
ExpiresByType application/x-font-woff "access plus 12 month"
ExpiresByType image/icon "access plus 12 month"
ExpiresByType application/x-javascript "access plus 2 month"
ExpiresByType text/javascript "access plus 2 month"
ExpiresByType text/css "access plus 2 month"
ExpiresByType image/gif "access plus 2 month"
ExpiresByType image/png "access plus 2 month"
ExpiresByType image/bmp "access plus 2 month"
ExpiresByType image/jpeg "access plus 2 month"
ExpiresByType text/plain A1200
ExpiresByType application/x-shockwave-flash "access plus 2 month"
ExpiresByType video/x-flv "access plus 2 month"
ExpiresByType application/pdf "access plus 2 month"
ExpiresByType text/html A6000
</IfModule>

<IfModule mod_headers.c>
<FilesMatch "\.(ttf|otf|woff|svg|ico|pdf|flv|swf|js|css|gif|png|jpg|jpeg|ico|txt|html|htm)$">
Header set Cache-Control "max-age=2592000, public"
</FilesMatch>
</IfModule>

<IfModule mod_headers.c>
  <FilesMatch "\.(js|css|xml|gz)$">
    Header append Vary Accept-Encoding
  </FilesMatch>
</IfModule>

<IfModule mod_gzip.c>
  mod_gzip_on Yes
  mod_gzip_dechunk Yes
  mod_gzip_item_include file \.(html?|txt|css|js|php|pl)$
  mod_gzip_item_include handler ^cgi-script$
  mod_gzip_item_include mime ^text/.*
  mod_gzip_item_include mime ^application/x-javascript.*
  mod_gzip_item_exclude mime ^image/.*
  mod_gzip_item_exclude rspheader ^Content-Encoding:.*gzip.*
</IfModule>

<IfModule mod_headers.c>
  Header set Connection keep-alive
</IfModule>

Posted by: servlet Nov 16 2018, 05:44 PM

Нещо не работи последната версия... да не би нещо да не е съобразено с ПХП7.1+

Posted by: Web Design Seo Nov 17 2018, 11:47 AM

Няма как да не работи ако имаш mod_expires и mod_deflate на сървъра, работи в момента чудесно на над 200 сайта. Работи на всеки споделен хост.

Може да се направят и още доста неща, но те са различни за всеки сайт и са вече за професионалости, докато този копи-пейст код е за всеки, дори да не знаеш кое какво е и да не можеш да програмираш.

Всъщност кода може да не работи само на някой нов или лошо настроен ВПС който няма качени mod_expires и mod_deflate - без тези два модула на сървъра аз не си позволявам да пусна сайт, но някои сис-админи си мислят, че може да си вземат заплатите и като претупат работата... по спомен някога съм виждал ВПС който ги е нямал и съм писал на суппорта на доставчика да ги качат.

Powered by Invision Power Board (http://www.invisionboard.com)
© Invision Power Services (http://www.invisionpower.com)