Mar 102013
 
Share this article...Share on FacebookTweet about this on TwitterShare on Google+Share on RedditShare on LinkedInPin on PinterestShare on StumbleUponShare on TumblrEmail this to someone


The .htaccess file is the standardized Apache specific configuration file and is leveraged by most hosting providers that support WordPress blogs.  Unless you are running on a Windows hosted environment with IIS servers and therefore you wouldn’t have a .htaccess file chances are your WordPress blog is using a .htaccess file to handle everything from how the site content is structured, URL’s are rewritten to any custom redirects you may have put in or leveraged plugins to handle.

image

Many WordPress plugins will write their own entries to the .htaccess file as well, some are more graceful and use comment tags to indicate where their custom entries are added, and will also gracefully remove them when plugin is disabled or removed.  Others may not be as graceful and may have a risk of damaging your .htaccess file so you should make sure this file like your normal WordPress blog files are backed up on a regular basis.

image

Example of good Begin/End Comment tags that keep plugin only writing to a specific area.

In normal cases you wouldn’t have to manually touch your .htaccess file but there may be some considerations where you may want to.  Here are some examples where you will want to update your .htaccess file manually so you don’t have to install a WordPress plugin.

Remove Directory Indexing

Directory Indexing is when a user hits your website and there is no index homepage (like index.php, index.html, index.htm…etc) you will see a list of files on the server instead of any specific page.  This is a security vulnerability if someone goes to your www.myblog.com/wp-content/plugins for example and they would see a list of your plugins you have installed for WordPress.  To prevent this from happening you simply add the following statement in your root .htaccess file (the one at the top folder in your wwwroot directory) or you can create a custom .htaccess file for each folder where you want to remove directory indexing.

In the .htaccess file just add:

#Remove Directory Indexing

Options All -Indexes

Once this is saved you won’t be able to see a list of directories or files in that folder anymore and this helps secure your wp-admin, wp-plugins and themes folder from being visible as well as any other custom folders you may have created.

Custom Redirects

Often referred to as URL masking or cloaking, it really isn’t it is just a redirect.  You basically usually want to take an affiliate link that you have and make it look like it is just going to your site.  You see this often, like going to www.myblog.com/go/myfavoriteproduct and it will redirect to myfavoriteproduct.com?youraffiliateID

This typically can be done with plugins and there are many good ones, but all plugins add some overhead with some more than others.  This overhead grows rapidly the more you have.  It is more efficient and faster if you build manual redirects in the htaccess file but this method works better if have very specific products and have a smaller number that you want to specifically target.  If you do multiple affiliate marketing to services like Amazon Affiliate or other programs where you are constantly grabbing links, images and want to link then a plugin may be easier and preferred.

To add a custom redirect to an .htaccess file simply open up the .htaccess file in your root web folder (the one above wp-content usually called wwwroot) and add the following line.

redirect /uri-prefix/uri-product http://www.youraffiliateproductlink.com

uri-prefix is some standardized virtual folder you want to use to indicate everything to this folder will be redirected, you need to make sure you don’t have a redirect possibly conflict with a blog post URI so you should put a pre-fix folder.  This could be something like /go, /recommend, /buy…etc.  Many use /go as the default.

uri-product is basically a short version of the product name like /go/greenipadcase if you were redirecting to your favorite green iPad case that you affiliate market for example.

You can have as many of these type of redirects as you want for example:image

Again, custom redirects in the .htaccess file will process faster and cause less overhead than using plugins but if you need dozens it is probably better to use a WordPress plugin.  You also lose all of these links if your .htaccess file is corrupted or replaced which is why it is important to backup the .htaccess file often.

WWW Redirect

One function of the .htaccess file is to ensure your website is loaded the same way and is indexed by Google as a single URL.  All websites might be able to be reached by both mywebsite.com and www.mywebsite.com but you will want to only allow 1 or the other.  Typically it is better to use the standardized www.mywebsite.com format for many reasons including thinking about users who may be behind proxy servers that may blog non www. based sites.

To do this most hosting providers have the ability to enable this feature for you with a click, but you can easily implement this yourself via a .htaccess file change to.

Just edit your root .htaccess file and add these statements

#Redirect all non-www to www.yoursite.com
RewriteCond %{HTTP_HOST} ^yoursite.com$
RewriteRule (.*)$ http://www.yoursite.com/$1 [R=301,L]

These statements say that anybody who hits your site as yoursite.com will automatically redirect to the same page on www.yoursite.com this also prevents Google from indexing 2 versions of your site and only indexes the www. version of your site.

Example of the lines in .htaccess file:image

 

Full Website Redirect

Let’s say you have a new website or moved from .org to .com or some other variation of your website, you will want to do a full website redirect so the homepage and every link from your original site redirects to your new site until Google picks up the updates and indexes the new site properly.  You will do this with 301 redirect statements in the Apache .htaccess file.

Replace your entire .htaccess file content on your original site (the one you want to redirect to new site) with these lines:

Options +FollowSymLinks
RewriteEngine on
#
RewriteCond %{HTTP_HOST} !^www\.yournewsite\.com
RewriteRule (.*) http://www.yournewsite.com/$1 [R=301,L]

In Summary

These are just some of the lines and items that may lurk in your .htaccess file or types of statements you may want to add to both help secure your WordPress installation, make affiliate links more user friendly and easier to remember if you use them repeatedly and to make sure only 1 version of your site is accessible and indexed by Google.

Again, there are WordPress plugins that can do some of these things but minimizing the number of plugins you have installed can help keep your WordPress blog having better performance so I would minimize plugins unless you need them.  I do recommend you use W3 Total Cache as a caching plugin which adds many caching statements to your .htaccess file.


Share this article...Share on FacebookTweet about this on TwitterShare on Google+Share on RedditShare on LinkedInPin on PinterestShare on StumbleUponShare on TumblrEmail this to someone
Justin Germino
Working in the IT Industry for over 13 years and specializing in web based technologies. Dragon Blogger has unique insights and opinions to how the internet and web technology works. An Avid movie fan, video game fan and fan of trying anything and everything new.
Justin Germino

@dragonblogger

Technology, Gaming and Wordpress blogger who runs gadget giveaways, helps others with blogging tips, monetization, earning and more!
SteamFeed TV (Ep.15): Copyblogger Kills Facebook, Parents Responsible For Kids' #SocialMedia http://t.co/yxvzN1xUYz via @SteamFeedcom - 3 hours ago
Justin Germino
  • http://tomjamieson.wordpress.com Tom Jamieson

    Justin, this is very helpful. I always wondered how to do the “/go” redirect. Thanks for sharing.

    • http://www.dragonblogger.com Justin Germino

      You are welcome, some plugins do this dynamically as mentioned but sometimes if you have very specific and hardcoded affiliate links why use a plugin when you can do it manually.

      Justin Germino
      http://www.dragonblogger.com http://www.justingermino.com
      http://www.wpcypher.com

      Facebook Twitter LinkedIn
      Twitter Latest tweet: SEO This Year: Links You Should Be Looking For http://t.co/6wy91AOahV via @dukeo Follow @dragonblogger Reply Retweet 10:40 Mar-10

      Get this email app!
      Latest post: Just 2 days until Starcraft 2: Heart of the Swarm? Who has bought it or plans on buying it?

      Like · Comment · Share Dragonblogger page on Facebook Like

      Get this email app!
      Designed with WiseStamp – Get yours

  • hotel deals

    hi,

    amazing in this blog very useful post you done good job,