WordPress accelerate GZip compression

What is Gzip compression, why use Gzip compression

Bluntly is a compression technology, it will request the browser file compression on the server side, and then compress the file passed to the browser, and then in the browser-side decompression, restore after the resolution. At present, 99% of the browser support Gzip, including IE 4+, Netscape 4+, Opera 5+ and all versions of Safari and Firefox, so we can rest assured that use.

Here we compress objects are all the HTML, and JS, and CSS. And this amazing compression efficiency can be reduced from 60% to 70%. Like my blog a 10K JS file, compressed with Gzip browser receives only 3 k size 16K CSS file was compressed into a 5 k, very powerful!

How to know if my pages are GZIP compressed

There are many ways to Gzip, and have access to the server is switched on by default Gzip compression, but as far as I know, very few such servers. How to determine whether your Web pages are Gzip! The test site has also a lot of online sites, but generally only to test HTML, here we recommend to you a test site: Websiteoptimization, enter the URL, enter the verification code, it will give your Web Page Speed Report.


Looks like a lot of “children’s shoes” wrong, and now make up the map! Which in the following Page Objects, will give all the files loaded by the information. In the last column of information, if you see: Congratulations! This file was compressed. Description is compressed, if it shows: Up to **** bytes could have been save through compression, apparently it has not yet been compressed.

Enable GZIP methods

Yes, there are several methods for different situations.

1, the best is your host is using Apache 2, and the installation of the mod_deflate module is enabled. It’s simple, just in .htaccess files can be compressed by adding the following code in HTML, PHP, JS, CSS, XML file suffix.

This is very simple, just add the following code in the .htaccess file can be compressed HTML, PHP, JS, CSS, XML suffix file.

<ifmodule mod_deflate.c>
AddOutputFilterByType DEFLATE text/html text/css text/plain text/xml application/x-httpd-php application/x-javascript
</ifmodule>

However, the general hosts do not have this module, if you are independent of the host can be configured. As for how to detect their own host whether to install this module, I really could not find a way, hope expert guidance. If you are interested, you may add the above code to see if Gzip could try it out! The above method from: I love boiled fish

2, using PHP to compress

This method also requires a PHP module zlib support, but this is a basic module, generally open!! So we focus on this section.

Compress dynamic pages with PHP

We first look at the so-called html compression, in fact, is dynamically generated by the PHP html. There are a number of ways, I use the shawn method.

PHP compresses JS and CSS

About JS and CSS also has several methods of compression and is currently more like K2 learning, JS and CSS to. php method. The predecessor has been introduced, please move: a brief introduction to WP blog style sheet and JS script compression

The disadvantage of this method is to modify each of the JS and CSS files, a bit less convenient. For all plugins in the JS and CSS are fairly easy merging blog, but no merger is undoubtedly a huge project, and the plug-in update is a troublesome thing. Look good in the CSS files into PHP, which look very strange, huh!! The advantage is that there is good adaptability, because the K2 method used!

The second method is to provide the old N method: speed up the blog, compression js,CSS, reduce bandwidth, this method should be said to be relatively simple, and the default for all the JS and CSS to take effect. Principle is that the JS and CSS using .htaccess compress to a PHP file to deal with the compression process.

Old N that seems to reproduce the code with some problems, I posted it again, huh, huh:

1, Create a gzip.php file and upload to the blog root directory, the code is as follows:

Download: gzip.php<?php
$allowed = array(
‘css‘ => ‘text/css‘,
‘js‘ => ‘text/javascript‘,
‘html‘ => ‘text/html‘,
‘htm‘ => ‘text/html‘,
);
$file = isset($_GET[‘url’]) ? $_GET[‘url’] : null;
$extension = explode(‘.‘, $file);
$extension = array_pop($extension);
if(isset($allowed[$extension]))
{
$pos = strpos($file, ‘..‘);
if ($pos === false && is_file($file))
{
@ob_start (‘ob_gzhandler‘);
header(“Content-type: {$allowed[$extension]}; charset: UTF-8“);
readfile($file);
} else {
header(‘HTTP/1.1 404 Not Found‘);
}
}
?>2、更改.htaccess文件,在.htaccess中添加:

RewriteCond %{REQUEST_FILENAME} -f
RewriteCond %{REQUEST_FILENAME} ^.*\.(css|js|html|htm)$
RewriteRule ^ (. *) $ Gzip.php? Url = $ 1 [QSA, L] on the OK, it is very simple

But there is a problem in two ways, eats server resources, and uses some CPU and memory, because every visit to the page to execute. But eat to what extent, I don’t know, it is said that in the case of tight server resources, compression efficiency is relatively low, but I think in general a large hosting provider or the host won’t have any problems.

The third way we look at the provision of radiation fish
  1. Download the Gzip.php file and upload it to your WordPress installation directory
  2. Create a wp-cache folder in your WordPress root directory and make sure it’s writable
  3. In the .htaccess which added

RewriteRule (. *. Css $ |. *. Js $) gzip.php? $ 1 [L]

Very simple, but the advantage of this method is: automatically reads and gzip compressed js and CSS access directly generated by calls to the .gz files, saving bandwidth or server resources, but not for space to install multiple WordPress blog, may lead to some second-level directory of the WordPress CSS style could not be loaded.These are the original words of radiation fish, Oh! The other is when the CSS and JS are updated manually to clear the cache. Meet the conditions of comrades recommended in this way! .

———————————————————–

WordPress 2.5 it failed after GZip function. You can use the following methods to open:

Method 1:

Found in the index.php in the root directory:
define(‘WP_USE_THEMES’, true);
Followed by:
ob_start(‘ob_gzhandler’);
It will be OK.

You can also add conditional judgment:
If (ereg (‘gzip’,$_SERVER[‘HTTP_ACCEPT_ENCODING’])) {//determine whether the browser supports Gzip
If (substr ($_SERVER[‘REQUEST_URI’],0,10)!=’/WP-content/uploads/’)//exclude a directory does not need to Gzip compression
ob_start(‘ob_gzhandler’); Turn on Gzip compression
}

Method 2:

If the Server supported .htaccess files in the WordPress root directory. htaccess add the following code without the. htaccess is increased after the new code. Increase after you complete the upload to your WordPress root directory.
php_value output_handler ob_gzhandler

Method 3:

Enable Gzip via php.ini
If the server supports the PHP.ini to redefine words, you can add the following code to turn on gzip in PHP.ini.
Zlib.output_compression_level = < any 1-9 value 1 compression ratio recommended is 6 >

Needs to pay attention if a. htaccess files prohibit the gzip function, it opens in the PHP.ini file to be in. htaccess file to open, or otherwise invalid.
Open WordPress gzip function, server transfer page page compressed before transmission, can effectively reduce server bandwidth usage, also speeds up page downloads.
On this site you can view the page if GZip is enabled, the compression ratio, and the opening page.

 

What is .htaccess?

Unix, and Linux systems or any version of the Apache Web server is supporting .htaccess, but some service providers may not allow you to customize your own .htaccess files. Most of the domestic virtual host will not have this function.

To enable .htaccess, you need to modify httpd.conf, enable AllowOverride, and use AllowOverride to restrict the use of specific commands. If you need to use the .htaccess other than the file name, you can use the AccessFileName command to change. For example, if you need to use. config, it can be configured in the server configuration file as follows: AccessFileName. config.

Generally speaking, the .htaccess can help us to achieve include: folder password protection, the user is automatically redirected, custom error pages, change the file name extension, ban specific IP addresses of users, allows only a specific list of users, directory listing, and the use of other documents as an index file and some other features.

The following describes the specific .htaccess file function settings

How to create a .htaccess file

.htaccess is a weird file name (from Win’s perspective, it does not have a file name, only a 8-letter extension, but in fact it is the name of linux, and many things under linux, we In the Win system is not directly through the “new” file to create, but we can use the cmd in the copy to achieve, such as copy sample.txt .htaccess. You can also create a htaccess.txt, then Ftp to the server, through FTP to modify the file name.

How to customize error pages

One application of .htaccess is a custom error page, that will allow you to have your own, personalized error pages (for example, file not found), instead of the error page provided by your service provider or do not have any pages. This will make your site look more professional when errors occur. You can also use scripts to notify you when an error occurs (such as when a page not found will automatically email you). You know any page error code (for example, 404 page not found), are accessible through the .htaccess file adding the following text turn it into a custom page:

ErrorDocument errornumber /file.html

For example, if my root directory has a notfound.html file, I would like to use it as a 404 error page:

ErrorDocument 404 /notfound.html

If the file is not under the root directory of the Web site, you only need to set the path to:

ErrorDocument 500 /errorpages/500.html

The following are some of the most common errors:
401 – Authorization Required needs validation
400 – Bad request error request
403 – Forbidden forbidden
500 – Internal Server Error
404 – Wrong page – page not found

Next, you need to do is create a file to display when an error occurs, and then take them. htaccess to upload.

.htaccess file of frequently used commands

First, prohibit the display of directory list
Sometimes, for some reason, there is no index file in your directory, which means that when someone types the path to the directory in the browser address bar, all the files in that directory are displayed, which will give your web site a security risks. To avoid this situation (without having to create a bunch of new index files), you can type in the following commands in your .htaccess document to prevent visitors from accessing your directory.

Directory listings are displayed:

Options -Indexes

Second, block/allow specific IP addresses
In some cases, you may want to allow only specific IP of users can access your Web site (for example: the specific ISP’s users are only allowed to enter a directory), or to ban certain IP addresses (for example: the low-level user isolation in the your information section). Of course, this is only useful if you know the IP address you want to block, but most users on the network now use dynamic IP addresses, so this is not a common way to limit usage.

You can block an IP address by using:
deny from 000.000.000.000

Here 000.000.000.000 is a banned IP address, if you only specify a few of them, you can block the entire network segment address. If you enter 210.10.56., All IP addresses of 210.10.56.0 to 210.10.56.255 will be blocked.

You can use the following command to allow an IP address to access the site:
allow from 000.000.000.000

Allowed IP addresses for 000.000.000.000, you can block IP addresses allow the entire network segment.

If you want to prevent all access to the directory, you can use:
deny from all

But this does not affect the script to use this directory under the document
The .htaccess file (or “distributed configuration file”) provides a way to change the configuration for a directory by placing a file containing one or more instructions in a specific document directory to act on the directory and all its subdirectories As a user, the commands that can be used are restricted, and the administrator can set it by Apache’s AllowOverride directive.

– Directives in subdirectories override instructions in the higher-level directory or in the master server configuration file.
– .htaccess must be uploaded in ASCII mode, preferably with permissions set to 644.

Location of error documents

Commonly used client request error Return Code:
401 Authorization Required
403 Forbidden
404 Not Found
405 Method Not Allowed
408 Request Timed Out
411 Content Length Required
412 Precondition Failed
413 Request Entity Too Long
414 Request URI Too Long
415 Unsupported Media Type

Common server returned error codes:
500 Internal Server Error

Users can use. Htaccess specified their own prior to make a good error reminder page. In general, people can specifically set up a directory, such as errors placed these pages. Then. Htaccess, add the following instructions:

ErrorDocument 404 /errors/notfound.html
ErrorDocument 500 /errors/internalerror.html

One instruction line. The first instruction is the meaning of 404, that is not found in the required documents when the page is displayed / errors directory notfound.html page. It is not difficult to see the syntax format:
ErrorDocument Error code / directory name / filename. Extension
If you need to prompt the information is very small, do not have special pages, direct use of HTML in the directive, for example, the following example:
ErrorDocument 401 ”
You do not have permission to access the page, please give up!”

Password protection for document access

To use .htaccess to a directory of the document set up to access the user and the corresponding password, the first thing to do is generate a. Htpasswd text documents, such as:

Zheng: y4E7Ep8e7EYV

Here the password is encrypted, the user can find some tools to encrypt the password. Htaccess support encoding. The document is best not to put on the www directory, the proposed directory on the www outside the directory, so that more secure.

With the authorized user documentation, you can add the following directive to the .htaccess file:

AuthUserFile .htpasswd The server directory
AuthGroupFile / dev / null (need to access the directory)
AuthName EnterPassword
AuthType Basic (authorization type)
Require user wsabstract (allow access to the user, if you want to allow all users in the table, you can use require valid-user)

Note, the brackets part of the learning time to add their own comments
Deny access from an IP

If I do not want a government department to access the content of my site, it can be .htaccess IP to join the department and reject them.

For example:
Order allow, deny
Deny from 210.10.56.32
Deny from 219.5.45.
Allow from all

The second line rejects an IP, the third line rejects an IP segment, which is 219.5.45.0 ~ 219.2.45.255

Want to reject everyone? With deny from all good. Not only with IP, you can also use the domain name to set.

Protect the .htaccess document
When you use .htaccess to set password protection for a directory, it contains the path to the password file. From the security point of view, it is necessary to protect. Htaccess up, let others see the contents. Although it can be done in other ways, such as document permissions. However, .htaccess itself can do, just add the following directive:
order allow,deny
deny from all
URL redirects

We could redesign the site, will migrate the document, or change the directory. At this time, access from search engines or other sites linked to it may be wrong. In that case, the old URL can be automatically redirected to the new address with the following command:

Redirect / Old Directory / Old Document Name The address of the new document
Or the entire directory of the steering:
Redirect Old directory New directory
Change the default home page file

In general, the default home page file name default, index and so on. However, there are times when there is no default file in the directory, but a specific file name, such as pmwiki.php in pmwiki. In this case, the user to remember the file name to access a lot of trouble. In .htaccess can easily set the new default file name:

DirectoryIndex The new default file name

You can also list multiple, in order that the priority between them, for example:
DirectoryIndex filename.html index.cgi index.pl default.htm

Prevent hotlinking

If you do not like people on their web pages to connect their own pictures, documents, it can also be done through the htaccess instructions.

Need instructions are as follows:
RewriteEngine on
RewriteCond % !^$
RewriteCond % !^http://(www.)? mydomain.com…*$ [NC]
RewriteRule . (gif|jpg)$ – [F]

If you feel that someone else’s page to open a skylight does not look good, it can use a picture to replace:
RewriteEngine on
RewriteCond % !^$
RewriteCond % !^http://(www.)? mydomain.com…*$ [NC]
RewriteRule . (Gif|jpg) $ http://www.mydomain.com/replace the picture file name [R,L]
source:http://wsabstract.com/howt… . .htaccess to achieve standardization of Web site

Web site standardization in SEO is a more important link, while the existence of different versions of the URL, not only may result in replication, but also can not focus on the right weight.

Most of the current site, domain names are bound with WWW and without two versions, and even many sites at the same time binding multiple domain names. After processing (jump, CNAME … …), for the visitors may not have any impact, see the same content; but for search engines, you can not determine which URL is the real home page.

Controllable factors, the site content link should keep the same version, such as the entire station, return to the home page address for a fixed version. But there is an uncontrollable factor, that is, someone else links to your site, the URL used. Many spontaneous links or exchange links, others may be omitted WWW, or use a binding of another domain name.

Uncontrollable external factors, we can be controlled from within the site. Using Apache .htaccess, use a 301 redirect, standard Web site.
Creates a new empty file, filename .htaccess, fill in the redirection rules, upload to the site root directory.

With 301 will not redirect the domain name with WWW
rewriteEngine on
rewriteCond % ^379.cc [NC]
rewriteRule ^(.*)$ http://www.379.cc/$1 [R=301,L]

Bound with a 301 redirect multiple domain names to the main domain name
RewriteEngine on
RewriteCond % ^379.cc$ [OR]
RewriteCond % ^bbs.379.cc$ [OR]
RewriteCond % ^luoyang.cc$ [OR]
RewriteCond % ^www.luoyang.cc$ [OR]
RewriteCond % ^bbs.luoyang.cc$
RewriteRule ^(.*)$ http://www.379.cc/$1 [R=301,L]

Of course, you can also extend, to redirect index.html, index.php, etc:
RewriteEngine on
RewriteCond % ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.379.cc/ [R=301,L]
Enabling SSI Via htaccess allows SSI (Server Side Including) functionality via htaccess
AddType text/html .shtml
AddHandler server-parsed .shtml
Options Indexes FollowSymLinks Includes
DirectoryIndex index.shtml index.html
Blocking users / sites by referrer Block user / site access according to referrer
mod_rewrite module is required

Case 1. Blocking a single referrer:badsite.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond % badsite\.com [NC]
RewriteRule .* – [F]

Case 2. Prevent multiple referrer:badsite1.com, badsite2.com
RewriteEngine on
# Options +FollowSymlinks
RewriteCond % badsite1\.com [NC,OR]
RewriteCond % badsite2\.com
RewriteRule .* – [F]
[NC]-case insensitive (Case-insensite)
[F] – 403 Forbidden

Note that the above code comments out the “Options + FollowSymlinks” statement. If the server does not set up FollowSymLinks in the httpd.conf paragraph, you need to add this, otherwise you will get “500 Internal Server error” error.

Blocking bad bots and site rippers (aka offline browsers) block bad crawler and offline browser
Needed mod_rewrite module
Bad spider? Like catch a junk email address crawler and does not comply with robots.txt reptiles (such as Baidu?)
They can be determined by HTTP_USER_AGENT
(But for some search engines to set their agent to “Mozilla / 4.0 (compatible; MSIE 5.5; Windows NT 5.0)”, can not do anything)
RewriteEngine On
RewriteCond % ^BlackWidow [OR]
RewriteCond % ^Bot\ mailto:craftbot@yahoo.com [OR]
RewriteCond % ^ChinaClaw [OR]
RewriteCond % ^Custo [OR]
RewriteCond % ^DISCo [OR]
RewriteCond % ^Download\ Demon [OR]
RewriteCond % ^eCatch [OR]
RewriteCond % ^EirGrabber [OR]
RewriteCond % ^EmailSiphon [OR]
RewriteCond % ^EmailWolf [OR]
RewriteCond % ^Express\ WebPictures [OR]
RewriteCond % ^ExtractorPro [OR]
RewriteCond % ^EyeNetIE [OR]
RewriteCond % ^FlashGet [OR]
RewriteCond % ^GetRight [OR]
RewriteCond % ^GetWeb! [OR]
RewriteCond % ^Go! Zilla [OR]
RewriteCond % ^Go-Ahead-Got-It [OR]
RewriteCond % ^GrabNet [OR]
RewriteCond % ^Grafula [OR]
RewriteCond % ^HMView [OR]
RewriteCond % HTTrack [NC,OR]
RewriteCond % ^Image\ Stripper [OR]
RewriteCond % ^Image\ Sucker [OR]
RewriteCond % Indy\ Library [NC,OR]
RewriteCond % ^InterGET [OR]
RewriteCond % ^Internet\ Ninja [OR]
RewriteCond % ^JetCar [OR]
RewriteCond % ^JOC\ Web\ Spider [OR]
RewriteCond % ^larbin [OR]
RewriteCond % ^LeechFTP [OR]
RewriteCond % ^Mass\ Downloader [OR]
RewriteCond % ^MIDown\ tool [OR]
RewriteCond % ^Mister\ PiX [OR]
RewriteCond % ^Navroad [OR]
RewriteCond % ^NearSite [OR]
RewriteCond % ^NetAnts [OR]
RewriteCond % ^NetSpider [OR]
RewriteCond % ^Net\ Vampire [OR]
RewriteCond % ^NetZIP [OR]
RewriteCond % ^Octopus [OR]
RewriteCond % ^Offline\ Explorer [OR]
RewriteCond % ^Offline\ Navigator [OR]
RewriteCond % ^PageGrabber [OR]
RewriteCond % ^Papa\ Foto [OR]
RewriteCond % ^pavuk [OR]
RewriteCond % ^pcBrowser [OR]
RewriteCond % ^RealDownload [OR]
RewriteCond % ^ReGet [OR]
RewriteCond % ^SiteSnagger [OR]
RewriteCond % ^SmartDownload [OR]
RewriteCond % ^SuperBot [OR]
RewriteCond % ^SuperHTTP [OR]
RewriteCond % ^Surfbot [OR]
RewriteCond % ^tAkeOut [OR]
RewriteCond % ^Teleport\ Pro [OR]
RewriteCond % ^VoidEYE [OR]
RewriteCond % ^Web\ Image\ Collector [OR]
RewriteCond % ^Web\ Sucker [OR]
RewriteCond % ^WebAuto [OR]
RewriteCond % ^WebCopier [OR]
RewriteCond % ^WebFetch [OR]
RewriteCond % ^WebGo\ IS [OR]
RewriteCond % ^WebLeacher [OR]
RewriteCond % ^WebReaper [OR]
RewriteCond % ^WebSauger [OR]
RewriteCond % ^Website\ eXtractor [OR]
RewriteCond % ^Website\ Quester [OR]
RewriteCond % ^WebStripper [OR]
RewriteCond % ^WebWhacker [OR]
RewriteCond % ^WebZIP [OR]
RewriteCond % ^Wget [OR]
RewriteCond % ^Widow [OR]
RewriteCond % ^WWWOFFLE [OR]
RewriteCond % ^Xaldon\ WebSpider [OR]
RewriteCond % ^Zeus
RewriteRule ^.* – [F,L]
[F] – 403 Forbidden
[L]-connection (Link)
Discuz! Forum static configuration rules are as follows:
# RewriteEngine model open
RewriteEngine On
# Modify the following statement in the/discuz directory of your forum address, if the program is placed in the root directory, please modify the/discuz to/
RewriteBase /
# Rewrite rules do not modify
RewriteRule ^archiver/((fid|tid)-[\w\-]+\.html)$ archiver/index.php?$1
RewriteRule ^forum-([0-9]+)-([0-9]+)\.html$ forumdisplay.php?fid=$1&page=$2
RewriteRule ^thread-([0-9]+)-([0-9]+)-([0-9]+)\.html$ viewthread.php?tid=$1&extra=page\%3D$3&page=$2
RewriteRule ^space-(username|uid)-(.+)\.html$ space.php?$1=$2
RewriteRule ^tag-(.+)\.html$ tag.php?name=$1

WordPress Video Tutorial 16 Disable AutoArchive Features Multiple Revisions

WordPress Getting Started Video Tutorial 16 – Disable auto-archiving of articles with multiple revisions of features

Automatically archive multiple revisions of the article, that is, revision, is WordPress added after the 2.6 version of the function. Each time you modify the log, it will add a revision, if you modify the log several times, this will be a terrible number. If you have hundreds of logs, your redundancy revision may be as many as a thousand. Revision Manager is for this, remove a large number of redundant revision to improve the speed of SQL statement execution, WordPress to improve the speed of running a great advantage.

Delete revision plugin to delete redundant multiple article versions revision control plugin to disable or control the automatic archiving multiple revisions of this part of the article content is very simple, but very useful. WordPress for WordPress Backup,archive, and will be a very important function. So try not to completely turn off the WordPress archive.

WordPress Video Tutorial 15 in the Host Space to Use WordPress to Pay Attention to the Place

Today’s lesson is when you use WordPress on a hosting space, two of the most important issues in need of attention.

The first big question: comment spam plugin Akismet to prevent and deal with comment spam plugin (WordPress plug-in introduced before mentioned the Akismet plugin) Akismet key:80e9452f5962 (you’d better apply it for yourselves, because more people will fail) WP-SpamFree comment spam prevention plugin

The second problem: database administration, maintenance, backup, plugin WP-DBManager

Management and maintenance of the database plugin WP-DB-Backup the database backup plugin each month or once every half month for database repair (repair DB) and database optimization (optimize DB). Backing up a database at any time.

About the error: Can not redeclare pclziputilpathreduction () Please disable the One Click Plugin Updater plugin and search or download the required plugins directly. PS: be sure to perform a database backup, and then upgrade WordPress . 2.7.1 before there is a log editor of the text color editor invalid, to 2.8 have been normal 🙂

WordPress Video Tutorial 14 To Achieve Pages, Categories, Links, Sort of Plug-ins

WordPress Getting Started Video Tutorial 14 – Plugins for sorting pages, categories, and links

We talked about the management of pages and links in Lesson 6, but the sorting of WordPress pages, categories, and links is also an essential feature of a complete WordPress log management system.

To achieve the three plug – ins sort: WordPress page sort plug – in My Page Order WordPress classification sort plug – ins

My Category Order WordPress Link Sorting Plugin My Link Order

Http://wordpress.org/extend/plugins/my-page-order/ http://wordpress.org/extend/plugins/my-category-order/ http://wordpress.org/extend/plugins/my- Link-order/

Since the use of these three plug-ins is really very simple, I began to also want to have no need to speak.

But taking into account the introduction will use the WordPress plug-in content integrity, or decided to mention it. Now it seems that our WordPress tutorial is indeed a zero-based friends, such a tutorial after reading, would like to not be immune!