Kohana v3 :: Godaddy & Megahosters
I have the opportunity (or problem, depending on my mood) to work with a diverse group of clients and many of the small business owners have hosting accounts with Godaddy, and one with Megahosters. Unlike most developers, I actually don’t mind godaddy so much, but, thats another post.
The point of this post is that I had to figure out how to get Kohana v3 working on Godaddy and Megahosters, so I thought I would pass the solution along
- Note: I am installing Kohana at the root of the domain in booth cases
- /.htaccess files
- Godaddy
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system) - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L] - Megahosters
AddHandler application/x-httpd-php5 .php
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ - [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]
- Godaddy
- /application/boostrap.php
At the bottom of the bootstrap file, after the routing, is the execution statement. By default it looks like this:
echo Request::instance()
->execute()
->send_headers()
->response;
Basically, you can pass an array when you instantiate the Request, but if you don’t (defualt), Kohana will use some If / Else statements to see which node of the $_SERVER array contains the request information. This works fine on most servers, but on shared servers like Godaddy/Megahosters, the first $_SERVER node (PATH_INFO) checked sends bad information, so to fix it, you just need to pass the Request the correct node. For both Godaddy and Megahosters, its the same: REQUEST_URI. So here is how it should look:
echo Request::instance($_SERVER['REQUEST_URI'])
->execute()
->send_headers()
->response;
HOPE THIS HELPS!
# Turn on URL rewriting
RewriteEngine On
# Installation directory
RewriteBase /
# Protect application and system files from being viewed
RewriteRule ^(application|modules|system)/ – [F,L]
# Allow any files or directories that exist to be displayed directly
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
# Rewrite all other URLs to index.php/URL
RewriteRule ^(.+)$ index.php?kohana_uri=$1 [L]