Accelerate WordPress With Better Permalink Rewrite Code

23 September 2013

Toronto: A latest WordPress blog employs an unoptimized url structure that employs numbers in place of the actual article titles. The so called permalinks need to be changed to switch from the number system to a system that is better readable for visitors and preferred by the search engines. It is for example possible to use urls that exhibit the category and page title as the url, to mix in dates, numerics or custom information.

The most significant rule for search engine optimization is to use the page title in the url. Everything else is optional and up to the user likes.

WordPress generates an .htaccess file when the permalinks are changed that comprises the rewrite directives. It sometimes happens that the file cannot be created or written which would then mean that the user would need to create and edit the htaccess file manually.

The WordPress code that is employed is not optimized. It does not put off for instance unnecessary file and directory checks. JP Morgan over at the Webmaster World forum created a better rewrite directive that "fixes several performance-affecting problems".

“This is a total replacement for the code supplied with WP as bounded by the "Begin WP" and "End WP" comments, and fixes several performance-affecting problems. Notably, the unnecessary and potentially-problematic container is completely removed, and code is added and re-structured to both prevent completely-unnecessary file- and directory- exists checks and to reduce the number of necessary -exists checks to one-half the original count (due to the way mod_rewrite behaves recursively in .htaccess context).

As per the JP the modified code speeds up the .htaccess code by at least a factor of two by “avoiding the second-pass exists checks on index.php itself, and avoiding exists-checks on resources such as image files which obviously don't need to be handled by WP.”

Put back the old WordPress rewrite code in the .htaccess file with the following new code. You might want to edit the file types (gif|jpg|php|ico|css|js). These should have the files that are requested the most. It might make sense to include png for instance in the list.

# BEGIN WordPress


RewriteEngine on


# Unless you have set a different RewriteBase preceding this point,

# you may delete or comment-out the following RewriteBase directive

# RewriteBase /


# if this request is for "/" or has already been rewritten to WP

RewriteCond $1 ^(index\.php)?$ [OR]

# or if request is for image, css, or js file

RewriteCond $1 \.(gif|jpg|php|ico|css|js)$ [NC,OR]

# or if URL resolves to existing file

RewriteCond %{REQUEST_FILENAME} -f [OR]

# or if URL resolves to existing directory

RewriteCond %{REQUEST_FILENAME} -d

# then skip the rewrite to WP

RewriteRule ^(.*)$ - [S=1]

# else rewrite the request to WP

RewriteRule . /index.php [L]


# END wordpress

This change seems to speed up the WordPress loading time considerably. Let us know how you think it affected the page loading time if you have implemented it in your blog or noticed a difference here at Ghacks.

Visit the thread over at the Webmaster World forum for extra information.

Read more: WordPress Web Development Toronto

News Archive

  • WordPress Development in Toronto
  • Drupal Development in Toronto
  • Joomla Development in Toronto
  • eCommerce Magento Toronto
  • Web Development Toronto
  • Web Design Toronto
  • jQuery development Toronto
  • Zend framework development Toronto
  • Airline IBE GDS Integration Navitaire Toronto
  • Airline IBE GDS Integration Aamadeus Toronto