OrangeWeb.

A Little Bit of Orange Never Hurt Anyone

More Useful HTACCESS Scripts

18 Jun 2009

In the previous article I was rambling about 301 redirects using a .htaccess file. In this article I will show a couple of other very useful htacess scripts that have been helpful in my time as a website designer.

First.

The following script will 301 redirect from a non WWW to a WWW. Meaning if you enter the url: http://domain.com.au it will automatically be redirected to http://www.domain.com.au. It is a personal preference, I think the having the WWW in the URL looks nicer, but not everyone will agree.

I have also read that it can help with SEO by removing any possibility of Google thinking there may be duplicate content. When linking to your website it is always best to pick one form (with www or without www) and stick with it, this script can help if the link is out of your control.

Code:
Options +FollowSymlinks
RewriteEngine on

Rewritecond %{http_host} ^yourdomain.com.au [nc]
Rewriterule ^(.*)$ http://www.yourdomain.com.au/$1 [r=301,nc]

If for some reason this is causing issues with your server try the following code. (It seems to work better with Joomla! 1.5)

Code:
Options +FollowSymlinks
RewriteEngine on

RewriteCond %{HTTP_HOST} ^yourdomain\.com\.au$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com.au/$1 [R=301,L]

Second.

The following script is to remove the ugly “index.php” on your homepage you can sometimes get when linking back to it.

For example: http://www.domain.com.au/index.php would simply become http://www.domain.com.au. I think that the URL without the index.php look much more attractive – again just my opinion.

Code:
Options +FollowSymlinks
RewriteEngine on
RewriteCond %{THE_REQUEST} ^[A-Z]{3,9}\ /index\.php\ HTTP/
RewriteRule ^index\.php$ http://www.yourdomain.com/ [R=301,L]
Posted by Michael Raffaele in Tutorials, Website Design | Permalink