htaccess tutorial tips for wordpress rewrite redirect leverage browser cache

  All .htaccess tutorial tips for WordPress and other platforms. rewrite, redirect 301, 302, permalink rewriting, keep alive, gzip leverage browser cache 301 redirection using .htaccess and other etc.

WordPress permalink redirection using htaccess

permalink post_id.html to post name  to
first of all, we have to redirect to
RedirectMatch 301 /29954.html(.*) /?p=29954$1
RedirectMatch 301 /[0-9].html(.*) /?p=[0-9]$1
RedirectMatch 301 /([0-9]+).html(.*) /?p=([0-9]+)$1
RedirectMatch 301 /([0-9]+).html(.*) /?p=$1 (worked)
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RedirectMatch 301 /([0-9]+).html(.*) /?p=$1
then 2nd url will automatically redirects to present URL.
Matching cases
RewriteRule ^([0-9]+)$ /$1
Options +FollowSymlinks
RewriteEngine on
RewriteBase /
RewriteRule ^([0-9]+)$.html /?p=([0-9]+)$1

This would redirect the following URL:



subdomain to main domain redirection

RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]


.htaccess rewrite rules

you can on off
.htaccess rewrite rules by using rewrite engine on or off

www to Non www redirection

RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

Non www to www redirection

RewriteCond %{HTTP_HOST} ^
RewriteRule (.*)$1 [R=301,L]

Redirecting to error page.

errorDocument 400
errorDocument 401
errorDocument 404
errorDocument 500

you need to add the above below the .htaccess file also you want place other third party website urls’ also which is redirecting to other domain.


leverage browser caching using .htaccess in wordpress

.htaccess tutorial tips for wordpress

you can HTTP header expire date if you using w3 total cache plugin wp super cache you don’t need to add this separately w3 total cache update it for you. 


<IfModule mod_expires.c>

ExpiresActive On

ExpiresByType image/jpg “access 1 year”

ExpiresByType image/jpeg “access 1 year”

ExpiresByType image/gif “access 1 year”

ExpiresByType image/png “access 1 year”

ExpiresByType text/css “access 1 month”

ExpiresByType application/pdf “access 1 month”

ExpiresByType text/x-javascript “access 1 month”

ExpiresByType application/x-shockwave-flash “access 1 month”

ExpiresByType image/x-icon “access 1 year”

ExpiresDefault “access 2 days”



how to enable keepalive using htaccess in wordpress website?

just add this code to your .htaccess

<ifModule mod_headers.c> Header set Connection keep-alive </ifModule>

what is keep alive?

it’s communication between browser and server.

Why we want use keep alive?

To reduce server load by keep living the loaded resources in browser.

you may check also .htaccess tutorial
related searches
.htaccess tutorial, .htaccess tutorial in php, .htaccess rewriterule,