Success story using .htaccess: speed up your board now!

Do not post support requests, bug reports or feature requests. Discuss phpBB here. Non-phpBB related discussion goes in General Discussion!
Anti-Spam Guide
User avatar
Dakoom
Registered User
Posts: 33
Joined: Sun Mar 08, 2015 12:24 pm

Success story using .htaccess: speed up your board now!

Post by Dakoom » Sat Sep 26, 2015 7:57 pm

I just want to share with you, guys and gals of this community, this usefull thing that I just tested on my board. It works great!

Before:
Load time
8.89s

Now:
Load time
2.26s

What is the trick?! Great! Open your phpbb/.htaccess file and add these rules:

Code: Select all

#
# Define Expires dates for static contnet
#   
ExpiresActive On
ExpiresByType text/css        "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType image/x-icon    "access plus 1 month"
ExpiresByType image/jpeg      "access plus 1 week"
ExpiresByType image/gif       "access plus 1 week"
ExpiresByType image/png       "access plus 1 week"

# compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# remove browser bugs
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


#
# Set the Cache control max-age = 1 week for CSS, JS, PDF and image file-types 
#
<FilesMatch "\.(css|js|gif|jpe?g|png|pdf)$">
   Header add "Cache-Control" "public, max-age=604800"
</FilesMatch>

#
# Omit Inode from Etag to prevent cache invalidation on server swap
#
FileETag MTime Size

#
# Set up DEFLATE compression from text stream types (Compression doesn't help on compressed formats such as JPEG) 
#  
AddOutputFilter DEFLATE js css
AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml application/xml

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

# 
# pass the default character set
#
AddDefaultCharset utf-8
DefaultLanguage it-IT

#
# set the server administrator email
#
SetEnv SERVER_ADMIN [color=#FF0000]admin@website.com[/color]

Options All -Indexes
#
# Deny access to forbidden directories and files
#
RewriteEngine   On
RewriteBase     / 
RewriteRule [color=#FF0000]community[/color]/(cache|files|includes|install-old|language|store)/  -  [forbidden]
RewriteRule /(\.|_|config\.php$|common\.php$)                          -  [forbidden]
Change the red texts using your own. For more info on what these rules does, check this article: https://wiki.phpbb.com/User:Terrye/Conf ... _for_phpBB. :mrgreen:
Last edited by Oyabun1 on Sat Sep 26, 2015 9:31 pm, edited 1 time in total.
Reason: Moved from 3.0.x Support forum
currently working on Klayz.com. phpBB at klayz.com/community/

Paph
Registered User
Posts: 362
Joined: Tue Dec 25, 2007 7:58 am
Location: Georgia - USA
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by Paph » Sun Sep 27, 2015 2:16 am

In this line

Code: Select all

AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml application/xml
shouldn't it be text/css instead of test/css?

Also, you say to open the .htaccess in your phpbb directory and add these changes, but the article you linked to said to add these changes in the root directory of your website, not in the forum directory.
Whenever practical, use a single .htaccess file in your web root directory to do what you need, and
Remove any .htaccess files in subdirectories, except in the rare occasions when directory-specific access files are the only way to achieve what you need. In the case of phpBB you should remove all .htaccess files provided in the standard install as these functions can be done more simply in the single central file.
Hawk

no_comment
Registered User
Posts: 67
Joined: Sat Dec 27, 2014 11:17 pm
Location: Hell
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by no_comment » Sun Sep 27, 2015 10:08 pm

Anyone tested this?

Paph
Registered User
Posts: 362
Joined: Tue Dec 25, 2007 7:58 am
Location: Georgia - USA
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by Paph » Sun Sep 27, 2015 11:15 pm

I haven't.
Hawk

User avatar
Solidjeuh
Registered User
Posts: 522
Joined: Wed Oct 06, 2010 11:20 pm
Location: Aalst / Belgium
Name: Andy Dm
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by Solidjeuh » Tue Sep 29, 2015 10:12 am

I tried this on my index page, But i notice no difference..
Maybe cause I'm on a dedicated server with 32 Gb Ram
Load time stays the same: Time: 0.437s
I don't suffer from insanity. I enjoy every minute of it.

nicofuma
3.2 Release Manager
3.2 Release Manager
Posts: 546
Joined: Sun Apr 13, 2014 1:47 am
Location: Grenoble - France

Re: Success story using .htaccess: speed up your board now!

Post by nicofuma » Tue Sep 29, 2015 5:35 pm

It doesn't change anything for the PHP side. What it does is that it activates the compression and the user land http cache to reduce the bandwidth usage, the number of requests for the assets and the user side load time.
Member of phpBB Development-Team
No Support via PM

User avatar
Dakoom
Registered User
Posts: 33
Joined: Sun Mar 08, 2015 12:24 pm

Re: Success story using .htaccess: speed up your board now!

Post by Dakoom » Tue Sep 29, 2015 8:03 pm

Paph wrote:In this line

Code: Select all

AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml application/xml
shouldn't it be text/css instead of test/css?
Thank you for this!
Also, you say to open the .htaccess in your phpbb directory and add these changes, but the article you linked to said to add these changes in the root directory of your website, not in the forum directory.
I added it both to the root and in the subfolders. :shock:
currently working on Klayz.com. phpBB at klayz.com/community/

User avatar
AmigoJack
Registered User
Posts: 5637
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by AmigoJack » Wed Sep 30, 2015 9:06 am

Dakoom wrote:

Code: Select all

AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

Code: Select all

AddOutputFilterByType DEFLATE text/html text/plain test/css text/xml application/xml
You're redundant - only define things once. Plus: you're enforcing compression, but there can still be clients which don't support it - and say so when requesting a resource. Maybe you'll understand it with this picture:
bootstrapcdn-vary-accept-encoding-2.png
Dakoom wrote:

Code: Select all

<FilesMatch "\.(css|js|gif|jpe?g|png|pdf)$">
JPeg files can also have .jpe and .jfif. Also: why not adding .ico, as website FAVICONs are requested very often (even without advertizing them)?
Dakoom wrote:

Code: Select all

Vary Accept-Encoding
This is for proxies (i.e. when you use a CDN), so only few people should actually need this.
Dakoom wrote:

Code: Select all

AddDefaultCharset utf-8
DefaultLanguage it-IT
Both things are not always right. Even worse: sending one of your phpBB attachments which is a text file is now understood by everyone to be in that encoding, which it surely is not. Do not use things like these, you don't seem to understand their impact! And they have also nothing to do with "load time".
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

User avatar
Dakoom
Registered User
Posts: 33
Joined: Sun Mar 08, 2015 12:24 pm

Re: Success story using .htaccess: speed up your board now!

Post by Dakoom » Wed Sep 30, 2015 9:18 am

Thank you somuch AmigoJack for your help. So, this is what I have now in public_html/.htaccess:

Code: Select all

#
# Define Expires dates for static contnet
#   
ExpiresActive On
ExpiresByType text/css        "access plus 1 month"
ExpiresByType text/javascript "access plus 1 month"
ExpiresByType image/x-icon    "access plus 1 month"
ExpiresByType image/jpeg      "access plus 1 week"
ExpiresByType image/gif       "access plus 1 week"
ExpiresByType image/png       "access plus 1 week"

# Compress text, HTML, JavaScript, CSS, and XML
AddOutputFilterByType DEFLATE text/plain
AddOutputFilterByType DEFLATE text/html
AddOutputFilterByType DEFLATE text/xml
AddOutputFilterByType DEFLATE text/css
AddOutputFilterByType DEFLATE application/xml
AddOutputFilterByType DEFLATE application/xhtml+xml
AddOutputFilterByType DEFLATE application/rss+xml
AddOutputFilterByType DEFLATE application/javascript
AddOutputFilterByType DEFLATE application/x-javascript

# Remove browser bugs
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

#
# Set the Cache control max-age = 1 week for CSS, JS, PDF and image file-types 
#
<FilesMatch "\.(css|js|jfif|ico|gif|jpe?g|png|pdf)$">
   Header add "Cache-Control" "public, max-age=604800"
</FilesMatch>

#
# Omit Inode from Etag to prevent cache invalidation on server swap
#
FileETag MTime Size

#
# set the server administrator email
#
SetEnv SERVER_ADMIN admin@klayz.com
currently working on Klayz.com. phpBB at klayz.com/community/

no_comment
Registered User
Posts: 67
Joined: Sat Dec 27, 2014 11:17 pm
Location: Hell
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by no_comment » Sun Oct 18, 2015 10:15 pm

I get this error:

Code: Select all

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster. 

User avatar
Lumpy Burgertushie
Registered User
Posts: 66812
Joined: Mon May 02, 2005 3:11 am
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by Lumpy Burgertushie » Mon Oct 19, 2015 3:00 am

most likely some part of what you put in the htaccess file is not supported by your server software/host.

most of that is simply not needed except in very specific situations and most people will never run into with their sites/hosting etc.


I would suggest removing all of it and unless you know what you are doing and have a specific need for any part of it, just don't worry about using it.

robert
I'm baaaaaccckkkk. still doing work on donation basis. PM your needs.

Premium phpBB 3.2 Styles by PlanetStyles.net

If a tree falls in the forest and nobody is there, does it make a sound?

User avatar
huyhoa
Registered User
Posts: 62
Joined: Sat Oct 02, 2004 4:39 am
Name: Huy Hoa
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by huyhoa » Mon Oct 19, 2015 4:06 am

no_comment wrote:I get this error:

Code: Select all

Server error!

The server encountered an internal error and was unable to complete your request. Either the server is overloaded or there was an error in a CGI script.

If you think this is a server error, please contact the webmaster. 
Check if you remove the code like:

Code: Select all

SetEnv SERVER_ADMIN [color=#FF0000]admin@website.com[/color]
It should be this:

Code: Select all

SetEnv SERVER_ADMIN admin@website.com
(without the color code)

If you do this, and still error, then your server may be exist some conflict with this setting.
I guess this code will do the static file cache on user browser and do some trick as Google speed ask to do to improved page load.

User avatar
AmigoJack
Registered User
Posts: 5637
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by AmigoJack » Mon Oct 19, 2015 7:15 am

Boys, if you edit .htaccess without knowing what to do in case of errors (looking up the HTTP server's error.log) then you should keep your hands off that entirely.
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

no_comment
Registered User
Posts: 67
Joined: Sat Dec 27, 2014 11:17 pm
Location: Hell
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by no_comment » Mon Oct 19, 2015 11:21 am

huyhoa wrote:Check if you remove the code like:

Code: Select all

SetEnv SERVER_ADMIN [color=#FF0000]admin@website.com[/color]
It should be this:

Code: Select all

SetEnv SERVER_ADMIN admin@website.com
(without the color code)

If you do this, and still error, then your server may be exist some conflict with this setting.
I guess this code will do the static file cache on user browser and do some trick as Google speed ask to do to improved page load.
Same error. :( Anyone tested this?

User avatar
AmigoJack
Registered User
Posts: 5637
Joined: Tue Jun 15, 2010 11:33 am
Location: グリーン ヒル ゾーン
Contact:

Re: Success story using .htaccess: speed up your board now!

Post by AmigoJack » Mon Oct 19, 2015 1:19 pm

Was my post too cryptic? The server.log will even tell you where an error took place (opposed to pointing to just a file without any line or position).
The worst thing about censorship is ███████████
Affin wrote:
Tue Nov 20, 2018 9:51 am
The problem is probably not my English but you do not want to understand correctly.
...
We will not come anybody anyway, nevertheless, it's best to shit this.

Post Reply

Return to “phpBB Discussion”