Speed Up WordPress With Better Permalink Rewrite Code

9 Gen/10

A new WordPress blog uses an unoptimized url structure that uses numbers instead 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 favored by the search engines. It is for instance possible to use urls that display the category and page title as the url, to mix in dates, numerics or custom information.

The most important rule for search engine optimization is to use the page title in the url. Everything else is optional and up to the user’s liking.

WordPress generates an .htaccess file when the permalinks are changed that contains 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 used is not optimized. It does not prevent 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).

According to 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.”

Replace the old WordPress rewrite code in the .htaccess file with the following new code. You might need to edit the file types (gif|jpg|php|ico|css|js). These should contain 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 additional information.

Continua a leggere – Original Link: Speed Up WordPress With Better Permalink Rewrite Code

Technorati Tags: , , , , , , , , , ,

Leggi Anche

Condividi in DeliciousCondividi in DiggCondividi in RedditCondividi in StumbleCondividi in MixxCondividi in TecnoratiCondividi in Ok Notizie


I commenti sono disabilitati per questo articolo.

I commenti sono chiusi.


    Spina Rosario
    Inserito da


Iscrizione Newsletter

    Tieniti informato con tutte le novità del mondo informatico con la nostra newsletter


    Auto Shop Italia
    Web Burning Blog
    Info Privacy