• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
htaccess for PHP-CGI hosting (and use segments with query strings)

This custom .htaccess setup allows you to use uri segments and query strings together and may fix the issue everyone seems to have running CI on PHP-CGI hosting.

The great thing is that CI allows us to use a custom defined uri protocol. (thanks Rick Ellis)

If you want to try this setup then read on.

Set your custom uri protocol in application/config.php
$config['uri_protocol'] = "APP_PATH";

//enable query strings if required.
$config['enable_query_strings'] = TRUE;

Create your .htaccess file like so
RewriteEngine On

RewriteBase /

RewriteCond %{ENV:REDIRECT_APP_PATH} !^$
RewriteRule ^(.*)$ - [E=APP_PATH:%{ENV:REDIRECT_APP_PATH}]

RewriteCond %{ENV:APP_PATH} ^$
RewriteRule ^(.*)$ - [E=APP_PATH:/$1]

RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php [L]

You should be good to go. Good luck.

Credit goes to the folks @ TinyMVC forum for this solution.

[eluser]Colin Williams[/eluser]
That is some dope-ass shit, wired. Good on ya' mate!

nice, this one works!
I'm making a repost on my site.

cool ^_^

it works for me partially. Now I can at least get into my home page. But that's it. From there what ever link I click it refreshes the home page even thought the URL changes according to the new link I clicks.

Any help?

Mine seems to work with just the two config changes. Is the .htaccess required or only in certain circumstances?

Thank you so much. My application was working fine on my local server, but when I uploaded it to my hosting server it broke. And it all had to do with my hosting server running PHP-CGI.

One thing I've noticed is that my application loads slower now that I've implemented this solution. Does anyone know why this happens or have a way to speed thing up.

Thanks mate... Thanks a lot!


Is there a way to make this work with CI 2.0? At the moment all system written links (redirect, pagination) get a additional /?/ added to the front.

should this approach add an APP_PATH variable to $_SERVER?

i try this, but everything seems to just redirect to the default controller, so the homepage only.

actually if i change the $config['uri_protocol'] = "REDIRECT_APP_PATH";

it does work. is this the wrong approach?

This will not work when you have your controller in subfolder? controller/admin/home.php

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.