WordPress and htaccess

Here are some sample lines to add to your .htaccess file to help WordPress run a little more smooth. Each line is commented so is pretty self explanatory.

#increase the memory limit available to PHP
php_value memory_limit 128M 

# give PHP scripts longer to execute
php_value max_execution_time 400 

#set the uplaod file size to 20M
php_value post_max_size 20M 
php_value upload_max_filesize 20M

#while writing code display errors, turn this one off when your live
php_value display_errors on 

This should go below the code that WordPress automatically generates that looks like this.

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>

# END WordPress

…..And use this to turn on browser caching

## EXPIRES CACHING ##
<IfModule mod_expires.c>
ExpiresActive On
# Good for one month
ExpiresByType image/jpeg A2592000
ExpiresByType image/gif A2592000
ExpiresByType image/png A2592000
ExpiresByType image/x-icon A2592000
ExpiresByType text/plain A2592000
ExpiresByType image/svg+xml A2592000
 
# Good for one week
ExpiresByType application/x-javascript M604800
ExpiresByType text/css M604800
ExpiresByType text/html M604800
ExpiresDefault A2592000
</IfModule>
## EXPIRES CACHING ##

… and finally ensure that you set mime types configured in your hosting environment so the above actually works

AddType image/gif .gif 
AddType image/jpeg .jpg 
AddType image/png .png
AddType image/svg+xml .svg
AddType image/svg+xml .svgz

Ok, I’ve copy and paste a few extra things into this post and I’ve picked them up on my travels, a bit of an explanation about the browser caching is in this newer post.

Comments

  1. Randy Caruso says:

    After 10 other sites – YOU had the right answer here… thank you. Nobody talks about WHERE to put the new text and you actually included notes: thank you. Well done. Thrashing my brains out over this at RackSpace under Cloudsites. Works now.

  2. Another little trick that I use is to override the PHP settings on the server.

    The following code turns on error reporting, you place it in the PHP file or even the function you’re working on to get PHP to display the errors for you.

    error_reporting(E_ALL);
    ini_set(‘display_errors’, ’1′);

  3. Found this useful post on htaccess, if you’re looking for more general things for htaccess you’ll be interested – 10+ things you can do with htaccess

  4. Thanks! This explanation really helped me out.

Trackbacks

  1. [...] been maintaining for a while a post over here where I list some useful settings for WordPress when setting up an .htaccess file. So refer to that [...]

Speak Your Mind

*