Saturday, 9 June 2007

Dealing with .htaccess files using godaddy! A true Lifesaver

Doesn't matter if you are happy with GoDaddy or not, if you have customers who have their own hosting choices and you didn't check this hosting firm yet, never mind, I can assure you the day is near... Oh well? Today? Had an .htaccess file for SEO freiendly URL's and it didn't work, uh?

The situation above was the case for me for several times. Though I had read GoDaddy's docs I couldn't manage to get .htaccess files running properly and let it down for the time being... until I realized they are using a directory system like y/o/u/yournamecom/html/foo/bar, and just two keystrokes solved my problem.
the rewrite part of my .htaccess file was as below:
Options Indexes FollowSymLinks MultiViews All

RewriteEngine on
# force trailing slash for real dircectories
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule [^/]$ %{REQUEST_URI}/ [R=301,L]

# ignore real files and directories
RewriteCond %{SCRIPT_FILENAME} -f [OR]
RewriteCond %{SCRIPT_FILENAME} -d
RewriteRule .* - [L]
RewriteRule !^index\.php$ index.php?path=$1 [NC,L]


Basically, this tells apache to redirect everything which is not index.php, with the exception of real files and directories. So, if I also have a foobar.php in the same directory as index, I don't want it re-targeted to index.
The directions above are quite straightforward and works with almost any other server, including my own local system (nowadays this is the most secure host, especially when I turn it off;-) )

This is quite obvious that I want to redirect any string after my domain name to index.php under the same directory. What if I'd want it re-targeted to foo/bar.php
Naturally directions will be slightly altered:
RewriteRule !^index\.php$ foo/bar.php?path=$1 [NC,L]


So what about the same directory? As we're on a GNU/Linux system, it's now a piece of cake to try to think of "dotslash" and voila!
RewriteRule !^index\.php$ ./index.php?path=$1 [NC,L]

Yes, it works! With only two keystrokes, we now have a working .htaccess file with GoDaddy.
I hope this will be useful for someone.


1 comment:

Unknown said...

Thank You...At last i fixed the error. :)