CodeIgniter Forums

Full Version: htaccess for PHP-CGI hosting (and use segments with query strings)
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2

El Forum

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.

El Forum

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

El Forum

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

cool ^_^

El Forum

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?

El Forum

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

El Forum

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.

El Forum

Thanks mate... Thanks a lot!


El Forum

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.

El Forum

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?

El Forum

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