tags:

views:

178

answers:

3

hi All,

I'm experimenting with codeigniter but don't really understand how links work.

for example, I have a link like this:

localhost/ci/welcome/cat/7

My base url is localhost/ci, so by clicking on this link I would expect the method "cat" of controller "welcome" to be called.

This method is very simple:

   function cat()
    { 
        echo "just a test.";
    }

Pretty basic - I would expect to see the text on screen, but I just see a 404 -page not found error.

What could be the problem?

+2  A: 

Have you configured mod_rewrite (or URL rewriting in general) properly for CodeIgniter? It's not supported out of the box.

They have some instructions in their wiki.

Veeti
I have this htaccess file:RewriteEngine onRewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)RewriteRule ^(.*)$ /index.php/$1 [L]I've copied it from the book I'm using to learn codeigniter, so I'm not entirely sure what it does. Do you think it's ok?
Patrick
PS don't know if it makes any difference, but I'm using MAMP
Patrick
Kind of a "delayed reply", but have you enabled mod_rewrite for Apache? You have to edit httpd.conf to do so.
Veeti
+3  A: 

http://localhost/ci/index.php/welcome/cat/7

Iraklis
doesn't work either..
Patrick
A: 

I had problems with the rewrite rule suggested in the user guide. I was also getting 404s. I had to remove the slash before index.php in the rule.

RewriteEngine on
RewriteCond $1 !^(index\.php|images|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]

As Veeti says, also remember to enable mod_rewrite for Apache.

Stephen Curran
Removed the slash but still doesn't work.I've checked the file httpd.conf (in mamp/conf/apache) and it contains this: LoadModule rewrite_module modules/mod_rewrite.soso I think the module is loaded correctly?I've tried with a few different links, and noticed that localhost/ci/welcome/test opens a google 404 ("oops! this link appears to be broken)while localhost/ci/index.php/welcome/test opens a codeigniter 404.Don't know whether this makes a difference?
Patrick
When you go to localhost/ci/index.php/welcome do you see the CodeIgniter welcome page?
Stephen Curran