Community Documentation

v3 Knowledgebase

Me and my PhpFox site

Firstly, I want to say thank you to data66.

I make this, just to share my short story in what am I doing on PhpFox V3.3.0. on share hosting. Most all of this is about PhpFox improvement. And in this tutorial I am trying to collect what I did for it. Of course this is not about everything I do. Because I'm sure, you've got your own way.

1. Me and .htaccess file.
Of course first of all I concentrated with htacess file. It gives me comfort, because a lot of things to do in this file. Although I know that some are not suitable for your server. Some of its contents are as follows:

# URL Rewrite
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{HTTP_HOST} !^$ [NC]
RewriteRule .*{REQUEST_URI} [R=301,L]

# Rename Photo Names
# RewriteRule ^file/pic/photo/([0-9]+)/([0-9]+)/([A-Za-z0-9]{32}+)-(.*?)([_0-9]*?).(.*)$ file/pic/photo/$1/$2/$3$5.$6

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*) index.php?do=/$1

# Image Access Protection
# RewriteRule ^file/pic/photo/(.*).(.*)$ static/image.php?file=$1&ext=$2

<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE  text/html text/css text/plain image/svg+xml text/javascript text/xml application/x-javascript text/js image/jpg application/x-httpd-php application/xhtml+xml application/rss+xml application/javascript application/x-httpd-fastphp application/json
<IfModule mod_setenvif.c>
BrowserMatch ^Mozilla/4 gzip-only-text/html
BrowserMatch ^Mozilla/4.0[678] no-gzip
BrowserMatch bMSIE !no-gzip !gzip-only-text/html
<IfModule mod_headers.c>
Header append Vary User-Agent env=!dont-vary
# END GZIPAddHandler mode-deflate mod_deflate

SetEnvIfNoCase User-Agent "^Baiduspider" UnwantedRobot
SetEnvIfNoCase User-Agent "^Yandex" UnwantedRobot
SetEnvIfNoCase User-Agent "^Exabot" UnwantedRobot
SetEnvIfNoCase User-Agent "^Cityreview" UnwantedRobot
SetEnvIfNoCase User-Agent "^Dotbot" UnwantedRobot
SetEnvIfNoCase User-Agent "^Sogou" UnwantedRobot
SetEnvIfNoCase User-Agent "^Sosospider" UnwantedRobot
SetEnvIfNoCase User-Agent "^Twiceler" UnwantedRobot

<FilesMatch ".(ico|pdf|flv|jpg|jpeg|png|gif|js|css|swf)$">
Header set Expires "Wed, 15 Apr 2020 20:00:00 GMT"
Header set Cache-Control "public"

<FilesMatch ".(avi|flv|mov|wmv|wma|mp3|mp4|m4a|mkv|swf|pdf|doc|ppt|ico|jpg|jpeg|png|gif|js|css)$">
  <IfModule mod_expires.c>
    ExpiresActive On
    ExpiresDefault A29030400

# BEGIN Cache-Control Headers
<IfModule mod_headers.c>
<FilesMatch ".(bmp|css|flv|gif|ico|jpg|jpeg|js|pdf|png|svg|swf|tif|tiff|php)$">
Header set Last-Modified "Mon, 31 Aug 2009 00:00:00 GMT"
# END Cache-Control Headers

Header unset Pragma
FileETag None
Header unset ETag

<FilesMatch ".(js|css|jpg|png|jpeg|gif)$">
RequestHeader unset Cookie
Header unset Set-Cookie
Header unset ETag
FileETag None

# Disable the server signature
ServerSignature Off

# Disable Libwww-perl Access
SetEnvIfNoCase User-Agent "^libwww-perl*" block_bad_bots
Deny from env=block_bad_bots

AddHandler application/x-httpd-php .css

# Pass the default character set
AddDefaultCharset utf-8

# Set the server administrator email

<FilesMatch ".(htaccess|htpasswd|ini|phps|fla|psd|log|sh)$">
Order Allow,Deny
Deny from all

# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*(.*) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (<|%3C).*script.*(>|%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})
RewriteRule ^(.*)$ /index.php [F,L]

# Deny access to evil robots site rippers offline browsers and other nasty scum
RewriteCond %{HTTP_USER_AGENT} ^Anarchie [OR]
RewriteCond %{HTTP_USER_AGENT} ^ASPSeek [OR]
RewriteCond %{HTTP_USER_AGENT} ^attach [OR]
RewriteCond %{HTTP_USER_AGENT} ^autoemailspider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xaldon WebSpider [OR]
RewriteCond %{HTTP_USER_AGENT} ^Xenu [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus.*Webster [OR]
RewriteCond %{HTTP_USER_AGENT} ^Zeus
RewriteRule ^.* - [F,L]

# Blocking based on User-Agent Header
RewriteCond %{HTTP_USER_AGENT} ^.*(craftbot|download|extract|stripper|sucker|ninja|clshttp|webspider|leacher|collector|grabber|webpictures).*$ [NC]
RewriteRule . - [F,L]

# Denies obvious trackback spam
RewriteCond %{HTTP_USER_AGENT} ^.*(opera|mozilla|firefox|msie|safari).*$ [NC]
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9} /.+/trackback/? HTTP/ [NC]
RewriteRule .* - [F,NS,L]
# Google Analytics Integration - Added by cPanel.
<IfModule mod_substitute.c>
AddOutputFilterByType SUBSTITUTE text/html
Substitute "s|(<script src='/google_analytics_auto.js'></script>)?</head>|<script src='/google_analytics_auto.js'></script></head>|i"
# END Google Analytics Integration

<Files *>
order deny,allow

# Cambodia (KH)
deny from

# Chinese (CN) IP addresses follow:
deny from 

# Hong Kong (HK)
deny from

# India (IN), Bangladesh (BD) and Pakistan (PK)
deny from

# Japan (JP) (hacking, scraping, or spamming)
deny from

# Korea (KR) IP addresses follow:
deny from

# Yahoo-Korea (provides free email services used by some spammers)
deny from

# Neighboring Asian countries:

# Malaysia (MY)
deny from

# Philippines (PH)
deny from

# Singapore (SG)
deny from

# Taiwan (TW)
deny from

# Thailand (TH)
deny from

# Vietnam (VN)
deny from


2. Me in compress most all of javascript files
Trying to arrange for all the javascript files are compressed. I use the service of Closure. Don't forget to click Reset Link before you use it. You just enter the URL of your file in there. There are three options of compression level, and you only have to adjust it. Once you click the Compile button, you will get a file compression results in the right column. If you get a warning message, lower the compression level, and repeat again to click the compile button.

What are the javascript file that I minimize? Almost all javascript files in folders static

This compression is important, at least in my opinion. Because the file size becomes smaller.

3. Me in compress most all of css files
a. Open your css file using Notepad or Notepad++ as free.
b. I usually use Yui to compress all css file in theme and on css static file on some module.
c. Open your css file one by one.
d. Copy your css code and paste in Code column on >> Choose file type as css >> Push Compress button >> Push Download Compressed File >> copy and paste all css code compressed and replace your old code.
e. Remember to make back up for every your css file. This is important if you are going to edit your css.
f. Upload and replace your css file with the compressed one.
g. Clear your site cache.
h. Done

4. Me in combine multiple css files.
Here just example regarding combine multiple css file. In PhpFox, I used to do it for small files, and css files from the module. For example, I use it for ultimate search module. I bought it a few days ago. In this module open module/cfsearch/template/default/block/search.html.php

I change:


and then put all code in the cfsearch.css into custom.css

5. Me and image background
Use images as little as possible in your template. No matter how small the size of the image, the image still image. It has a link that will be also invoked by the browser. If it can be replaced only by a color code, then replace.

Example on #mobile_header{background:url('../image/layout/mobile_header.png') repeat-x;}

You can replace with: #mobile_header{background:#005C69;height:40px;margin:0 auto;width:100%}

It's because, that code have the same result to make a background using color #005C69 with dimension height 40px and width 100%.

6. Me and combine some images
You can also combine some images into one. I often use Spriteme services to do it. Work fine on Firefox. With this service, you will be given a new image sprite with the new code, and how position of the image in the css code.

Just an example is:

This image is combine from holder_notify_friend_request.png, holder_notify_message.png, holder_notify_notification.png, main_search_bar_button.png, activity_feed_form_attach.png, profile_photo.png, and 5 others pictures.

7. Me and image
Based on gtmetrix's suggestion, we also need to give a dimension, alt and title for our image. Example is for banner.png on homepage. We can add width='530px' height='245px' alt="some-text-here" title="" for our image. It's will help your site score and SEO. This also applies to the logo and others.

Especially for the user pictures on homepage, I decided not to display it. This will reduce the number of http requests. If you're going to do it, you can delete this code:

<div class="user_welcome_images">{foreach from=$aUserImages name=userimages item=aUserImage}{img user=$aUserImage suffix='_50_square' max_width=50 max_height=50}{/foreach}</div>

in module/user/template/default/images.html.php

I actually have a few other tricks, but I think it's enough because my time is somewhat limited.

Thank you