Saturday, October 1, 2011

Easy SEO friendly htaccess and Nginx rules for Wordpress

Wordpress has always been SEO-friendly right from the box.But if you want it to be more,then here is a sample htaccess and Nginx rules that may help you.These rules redirect every errors to Wordpress error pages as well as forward non-canonical links to canonical links.Even non-www urls are redirected.

Save this as .htaccess:

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
RewriteCond %{HTTP_HOST} ^linuxdo\.blogspot\.com$ [NC]
RewriteRule ^(.*)$ http://www.linuxdo.blogspot.com/$1 [R=301,L]
</IfModule>
# END WordPress


--Replace linuxdo.blogspot.com with your webpage url.--

Insert this in Nginx virtual host conf file:

if (!-f $request_filename){
set $rule_0 1$rule_0;
}
if (!-d $request_filename){
set $rule_0 2$rule_0;
}
if ($rule_0 = "21"){
rewrite /. /index.php last;
}
if ($http_host ~* "^linuxdo\.blogspot\.com$"){
set $rule_1 1$rule_1;
}
if ($rule_1 = "1"){
rewrite ^/(.*)$ http://www.linuxdo.blogspot.com/$1 permanent;
break;
}


--Replace linuxdo.blogspot.com with your webpage url.--

Hope this helps.



1 comment:

  1. Great Post! Thanks a lot for sharing such a wonderful seo friendly article..word press is used to create SEO friendly website and blog so it is both free and priceless at the same time.

    ReplyDelete