CodeIgniter Forums
Yet another "index.php" problem - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Yet another "index.php" problem (/showthread.php?tid=2400)



Yet another "index.php" problem - El Forum - 08-02-2007

[eluser]Lionel H[/eluser]
Hello everybody,

I'm a french autodidact PHP developper ; I've just discovered CI and I really love it !

I have a "index.php" problem ; a sample of code is much clear than a long explanation :

"home" controller (set as the default controller in config/routes.php) :
Code:
class Home extends Controller {
    function Home() {
        parent::Controller();    
        $this->load->helper('form');    
    }
    
    function index() {
        $this->load->view('home_view');
    }
}

"home_view" :
Code:
<html>
...
<?= form_open('blog/insert') ?>
    <p>&lt;input type="text" name="titre" /&gt;</p>
    <p>&lt;textarea name="article" cols="40" rows="10"&gt;&lt;/textarea&gt;</p>
    <p>&lt;input type="text" name="auteur" /&gt;</p>
    <p>&lt;input type="submit" value="Poster" /&gt;</p>
&lt;/form&gt;
...
&lt;/html&gt;

"blog" controller :
Code:
class Blog extends Controller {
    function Blog() {
        parent::Controller();
        $this->load->helper('url');
    }
    
    function insert() {
        $this->db->insert('codeigniter', $_POST);
        redirect('home/index');
    }
}
So, everything work, except for the redirect() function ; I get this in my address bar :
http://myserver/ci/index.php/home/index.php/blog/insert and, of course, a 404 error.

Can I resolve this problem by removing the "index.php" ?
I've read The User Guide and The Wiki about removing the index.php, and many posts in forum too, but I'm not able at all to remove this "index.php" (I've tried many .htaccess configurations, on my local server on my Mac and on distant pro servers).

I'm sorry if this question has been already asked, but I've spent all the day to search the solution for nothing...
Thanks in advance ! :-)


Yet another "index.php" problem - El Forum - 08-02-2007

[eluser]foutrelis[/eluser]
Hello Lionel,

I had the same issue yesterday and I think the solution is to set the base url inside application/config/config.php ($config['base_url']).

I hope this helps Smile


Yet another "index.php" problem - El Forum - 08-02-2007

[eluser]Lionel H[/eluser]
Thank you Foutrelis, it works ! :-)
At the same time, I've just discovered the step 3 here.

I promise I'll RTFM.
I promise I'll RTFM.
I promise...
;-)

I'll try to get rid of the "index.php" in the address bar later, I have to keep on re-writing my website with CI...


Yet another "index.php" problem - El Forum - 08-02-2007

[eluser]foutrelis[/eluser]
You're welcome :-P

btw, I use this .htaccess to get rid of index.php (based on CI docs):

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php/$1 [L]
</IfModule>



Yet another "index.php" problem - El Forum - 08-04-2007

[eluser]Lionel H[/eluser]
Well, removing the index.php doesn't seem to work with all servers ; Free (a big french ISP) doesn't allow many arguments in the .htaccess file, and I get a 500 error for each .htaccess I've tried. So I leave this index.php for the moment ! ;-)


Yet another "index.php" problem - El Forum - 08-18-2007

[eluser]Carlton[/eluser]
Hi Lionel H,

I was following the instructions but still had problems with .htaccess

Is your server set up like http://localhost/CI/ ??
I think the instructions assume you are simply at http://localhost....try adding your directory name before the index.php...e.g. mine is CI

Code:
RewriteEngine on
RewriteBase /
RewriteCond $1 !^(index\.php|robots\.txt|css|images|jscript)
RewriteRule ^(.*)$ /CI/index.php/$1 [L]



Yet another "index.php" problem - El Forum - 08-19-2007

[eluser]Lionel H[/eluser]
Hello Cariton,

well, I haven't tried to do without the index.php since I posted here, because I had to finish a website. I'm really sorry, I still don't know how to do that...


Yet another "index.php" problem - El Forum - 08-19-2007

[eluser]alexsancho[/eluser]
@Carlton: you can try this instad

Code:
RewriteEngine on
RewriteBase /CI/
RewriteCond $1 !^(index\.php|robots\.txt|css|images|jscript)
RewriteRule ^(.*)$ index.php/$1 [L]



Yet another "index.php" problem - El Forum - 08-20-2007

[eluser]Carlton[/eluser]
Thanks Alex, I thought that's what that directive might be for.
Also if you call your css/images/javascript folders something other than css|images|jscript be sure to add them to the RewirteCond directive


Yet another "index.php" problem - El Forum - 08-20-2007

[eluser]alexsancho[/eluser]
To avoid this things I've normally use a slightly diferent directives

Code:
RewriteEngine On
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [L]

In plain english what i'm doing is redirecting all that doesn't really exists on server path to index.php