metinsaylan // rogue developer

Mastering “.htaccess” file tricks for WordPress

.htaccess is a file used by Apache server, to over-write general rules for certain folders. Previously, we shared how to speed up your website using .htaccess file. With this post, we see there is more, awesome ways to manage your server rules and limits.

Default WordPress .htaccess file

# BEGIN WordPress

RewriteEngine On
RewriteBase /
RewriteRule ^index.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]

# END WordPress

Enable Browser Caching for certain file types

## 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 ##

Read more about ExpiresByType

Redirect posts and pages to other URL

Redirect 301 /oldurl  http://MySite.com/newurl

Hide WordPress configuration files

<files wp-config.php>
order allow,deny
deny from all
</files>

Increase or Decrease file upload size limit

php_value post_max_size 20M
php_value upload_max_filesize 20M

Increase PHP memory limit

php_value memory_limit 128M

Turn PHP Error Display On

php_value display_errors on

Read more about enabling php error log using htaccess.

(Resource: Master .htaccess WordPress Controls)

Search Mastering “.htaccess” file tricks for WordPress on Google