How to Use a .Htaccess File to Improve Your Website

How to Automatically Redirect Users Using .Htaccess

B. Rock
If your website runs on an Apache server - and most do - you can use a .htaccess to do some pretty powerful things.

Want to automatically redirect your users to the feed you created at Feedburner? Yup, you can do that.

Want to automatically remove the 'www' from the URL people use to access your site? You can do that, too.

There are tons of reasons you might want to use a .htaccess file, and you could spend days learning the ins and outs of the Apache commands. To get you started, here are a couple of tips and tutorials found at Nerds at Work.

Redirect Users to Your Feedburner Feed

Most blogging platforms and CMSes automatically create an RSS feed for you. They then make it easy to automatically insert the URL to that RSS feed throughout your site.

That's great until you decide to create a page for your feed at Feedburner. This allows you to track lots of statistics about your feed and its subscribers - but only if people subscribe to your feed through the Feedburner page.

You could hack up your page's code to include the feedburner URL instead of the default URL - or you could use .htaccess.

With the .htaccess file, you can create a mod_rewrite command that will detect if a user is attempting to load your site's feed and then automatically redirect him to the feedburner page. A couple lines of code, and within a few minutes you can be sure that everyone is routed to your Feedburner page.

Read through the original tutorial for a detailed example and an explanation of how to redirect people to your feedburner feed with .htaccess.

How to Remove the 'WWW' from Inbound Links

You may not realize it, but the 'www' in most internet links is redundant. You simply don't need it.

What's more, if links to your page sometimes include the 'www' and sometimes don't include the 'www,' you may be penalized by search engines like Google and Yahoo.

Now if you can control everyone on the internet and convince them to use one standard or the other - go for it. A better method might be to use a .htaccess to automatically redirect users - and search engine spiders - and remove the 'www' from inbound links.

You need a simple mod_rewrite command that instructs Apache to look out for any request for a page that begins with 'www.' and your domain. The user is then redirected to the same address - without the 'www.'

It'll take you about five minutes to set up if you read through this tutorial on how to remove the 'www' from inbound links with htaccess.

Start Hackin Away at htaccess

What are you waiting for? Start playing around with your .htaccess.

These two tips are just the tip of the iceberg. You can do much more, like redirect users from an old website or domain to a new one, password protect files or directories, and convert URI requests into search engine friendly URL's.

But you can't do any of that if you don't start playing around with a .htaccess file and its possibilities.

Published by B. Rock

I'm a recent graduate, a newly wed, and a (no longer first year) teacher. I teach HS Social Studies in a New Jersey city. I graduated from the Rutgers Grad School of Ed in May of 2007. In July '07, I...  View profile

  • A .htaccess file allows the Apache web server to perform certain automated tasks.
  • You can automatically redirect users to an alternative RSS feed - like a Feedburner page.
  • You can automatically remove the 'www' from a URL when a user visits your site.

To comment, please sign in to your Yahoo! account, or sign up for a new account.