0

My current development is using CodeIgniter, and when I try to pass some parameters to index function of my main controller it returns me 404 error.

http://localhost/gis/1 -> 404 ERROR
http://localhost/gis/home/1 -> 404 ERROR

Actually my route.php file has a route like this:

$route['default_controller'] = "home";    

$route['home/([:num])'] = 'home/index/$1';

My .htaccess file is this (from this post to take away index.php from CI urls):

<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d

    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>

<IfModule !mod_rewrite.c>
    # If we don't have mod_rewrite installed, all 404's
    # can be sent to index.php, and everything works as normal.
    # Submitted by: ElliotHaughin

    ErrorDocument 404 /index.php
</IfModule>

And my config.php file:

$config['base_url'] = "http://localhost/gis";

$config['index_page'] = "";

What am I doing wrong? Thanks!

2
  • What is your default controller in routes.php ? Commented Feb 27, 2011 at 11:23
  • @Sarfraz I edit my own question Commented Feb 27, 2011 at 11:30

1 Answer 1

2

Update:

Quoting OP:

.htaccess wasn't guilty. The problem was that my route needs to be $route['home/(:num)'] = ... I added both parenthesis and all works.


Rather than:

$route['home/([:num])'] = 'home/index/$1';

Try specifying it like this:

$route['home/:num'] = 'home/index/$1';

Also make sure that from application/config/routes.php, your default controller is set to home:

$route['default_controller'] = 'home';
Sign up to request clarification or add additional context in comments.

4 Comments

Thanks for your quick answer. I tried what you said but it didn't work for me. If I try to print the parameter in my main controller index function, always print '$1'. Can you help me?
@Fran Verona: Try disabling the .htaccess file to check if there is something wrong in it.
htaccess wasn't guilty. The problem was that my route needs to be $route['home/(:num)'] = ... I added both parenthesis and all works. Can you edit your own answer to add this? Thank you so much Sarfraz.
@Fran: Glad to know it works, I think you were already using parentheses as in your question. I will update the answer though :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.