WordPress Ultimate .htaccess Hacks For better SEO

by admin on April 21, 2010

htaccess WordPress Ultimate .htaccess Hacks For better SEO

<image credit>

The .htaccess files (Hypertext Access file) is a very powerful configuration tool on Apache web server.

The Apache web server has a number of configuration options that are available to the server administrator.It can be found in the webroot of your server and can be easily edited using any text editor.

NOTE-Make sure to back up your current .htaccess file before applying any of the following hacks.

Redirect WordPress RSS feeds to feedburner

#Redirect wordpress content feeds to feedburner
<ifmodule mod_rewrite.c="">
RewriteEngine on
RewriteCond %{HTTP_USER_AGENT} !FeedBurner    [NC]
RewriteCond %{HTTP_USER_AGENT} !FeedValidator [NC]
RewriteRule ^feed/?([_0-9a-z-]+)?/?$ http://feeds.feedburner.com/yourfeed [R=302,NC,L]
</ifmodule>

Remove File Extension From URL

RewriteRule ^(([^/]+/)*[^.]+)$ /$1.php [L]

force the use of the browser cache

FileETag MTime Size
<ifmodule mod_expires.c>
  <filesmatch "\.(jpg|gif|png|css|js)$">
       ExpiresActive on
       ExpiresDefault "access plus 1 year"
   </filesmatch>
</ifmodule>

Redirect visitors to a maintenance

page

RewriteEngine on
RewriteCond %{REQUEST_URI} !/maintenance.html$
RewriteCond %{REMOTE_ADDR} !^123\.123\.123\.123
RewriteRule $ /maintenance.html [R=302,L]

Protect your WordPress from

hotlinking

RewriteEngine On
#Replace ?mysite\.com/ with your blog url
RewriteCond %{HTTP_REFERER} !^http://(.+\.)?mysite\.com/ [NC]
RewriteCond %{HTTP_REFERER} !^$
#Replace /images/nohotlink.jpg with your "don't hotlink" image url
RewriteRule .*\.(jpe?g|gif|bmp|png)$ /images/nohotlink.jpg [L]

Remove "category" from a URL

RewriteRule ^category/(.+)$ http://www.yourblog.com/$1 [R=301,L]

Block all requests from user agent

## .htaccess Code :: BEGIN
##  Block Bad Bots by user-Agent
SetEnvIfNoCase  user-Agent ^FrontPage [NC,OR]
SetEnvIfNoCase  user-Agent ^Java.* [NC,OR]
SetEnvIfNoCase user-Agent  ^Microsoft.URL [NC,OR]
SetEnvIfNoCase user-Agent  ^MSFrontPage [NC,OR]
SetEnvIfNoCase user-Agent  ^Offline.Explorer [NC,OR]
SetEnvIfNoCase user-Agent  ^[Ww]eb[Bb]andit [NC,OR]
SetEnvIfNoCase user-Agent  ^Zeus [NC]
<Limit GET POST HEAD>
Order  Allow,Deny
Allow from all
Deny  from env=bad_bot
</Limit>
##  .htaccess Code :: END

Redirect an old domain to a new domain

# redirect from old domain to  new domain
RewriteEngine On
RewriteRule ^(.*)$  http://www.yourdomain.com/$1 [R=301,L]

Enable gzip with htaccess

AddOutputFilterByType DEFLATE text/html text/plain text/xml application/xml application/xhtml+xml text/javascript text/css application/x-javascript BrowserMatch ^Mozilla/4 gzip-only-text/html BrowserMatch ^Mozilla/4.0[678] no-gzip

Implement a 301 Redirect

The first URL should be a relative path to the old URL and the second one should be an absolute path to the new URL.
Redirect 301 relative/path/to/oldurl/ http://www.domain.com/newurl/

Remove www from URL

#remove www from URI
RewriteEngine On
RewriteCond %{HTTP_HOST} ^www\.domain\.com$ [NC]
RewriteRule ^(.*)$ http://domain.com/$1 [L,R=301]

Disable Directory Browsing

Options All -Indexes

Force Caching

FileETag MTime Size
ExpiresActive on
ExpiresDefault "access plus 86400 seconds"

Add Trailing Slash to URL

#trailing slash enforcement
RewriteBase /
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_URI} !#
RewriteCond %{REQUEST_URI} !(.*)/$
RewriteRule ^(.*)$ http://domain.com/$1/ [L,R=301]

Limiting number of simultaneous

connections

MaxClients < number-of-connections>


stop spam comments

RewriteEngine On
RewriteCond %{REQUEST_METHOD} POST
RewriteCond %{REQUEST_URI} .wp-comments-post\.php*
RewriteCond %{HTTP_REFERER} !.*yourblog.com.* [OR]
RewriteCond %{HTTP_USER_AGENT} ^$
RewriteRule (.*) ^http://%{REMOTE_ADDR}/$ [R=301,L]


Protect your .htaccess file.


# STRONG HTACCESS PROTECTION</code>
<Files ~ "^.*\.([Hh][Tt][Aa])">
order allow,deny
deny from all
satisfy all
</Files>

Set the timezone of the server

SetEnv TZ America/Indianapolis

Sources :-

Avoiding the use of .htaccess for performance

Comprehensive guide to .htaccess

Stupid htaccess Tricks

Josiah Cole

Perishable Press

AskApache

Did you enjoy this article? Please subscribe to Email Newsletter to receive
 all the FREE updates!

Popularity: 80% [?]

Share and Enjoy:
  • Print
  • Digg
  • Sphinn
  • del.icio.us
  • Facebook
  • Mixx
  • Google Bookmarks
  • Add to favorites
  • BarraPunto
  • BlinkList
  • blogmarks
  • Blogosphere News
  • blogtercimlap
  • Current
  • Diggita
  • Diigo
  • DZone
  • Fark
  • Fleck
  • HealthRanker
  • HelloTxt
  • IndianPad
  • LinkedIn
  • Linkter
  • Live
  • MisterWong
  • MSN Reporter
  • MyShare
  • MySpace
  • Netvibes
  • NewsVine
  • PDF
  • Ping.fm
  • Posterous
  • Propeller
  • Reddit
  • RSS
  • Slashdot
  • SphereIt
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tipd
  • Tumblr
  • Twitter
  • Upnews
  • Wikio
  • Yahoo! Bookmarks
  • Yahoo! Buzz
  • Yigg

{ 1 comment… read it below or add one }

Bass Drum Mallets May 16, 2010 at 12:27 am

Hi there, Today by way of Google and your publish looks really interesting for me.

Reply

Leave a Comment

Previous post:

Next post: