0

I have codeigniter installed in root/igniter folder.

under root/igniter, I have the following .htaccess file:

RewriteEngine On
RewriteCond %{REQUEST_URI} ^/system.*
RewriteRule ^(.*)$ index.php?/$1 [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?/$1 [L]

Pages open just as I would expect them to without using 'index.php'. So, my home page lies at http://example.com/igniter and my registration page at http://example.com/igniter/registration opens as well.

However, in my registration form, the submit button which is handled by a CI controller redirects to

http://example.com/igniter/index.php/registration

I have made sure that my config.php under applications/config has

$config['index_page'] = "";

This is what my Registration controller looks like:

public function index()
    {
        $this->load->helper(array('form', 'url'));
        $this->load->model('Registration_Model');       
        $this->load->library('form_validation');
        $this->form_validation->set_error_delimiters('<div class="error">', '</div>');

        $this->form_validation->set_rules('username', 'Username', 'trim|required|min_length[5]|max_length[12]|callback_username_check|xss_clean');
        $this->form_validation->set_rules('password', 'Password', 'trim|required|min_length[6]|max_length[12]|matches[passconf]');
        $this->form_validation->set_rules('passconf', 'Password Confirmation', 'trim|required');
        $this->form_validation->set_rules('email', 'Email', 'trim|required|valid_email|callback_email_check');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('registration');
        }
        else
        {
            //input data into database here
            $username = strtolower($_POST['username']);
            $password = md5($_POST['password']);
            $email = strtolower($_POST['email']);

            $data = array
                    (
                        'username' => $username,
                        'password' => $password,
                        'email' => $email
                    );

            $this->Registration_Model->addUser($data);  
            $this->load->view('registrationsuccess');
        }
    }

As far as I can see, I am not explicitly asking the controller to redirect to index.php/registration.

1
  • 3
    I don't see any code that would redirect at all here. Are you sure it's not a problem with the form's action? You might want to show your view code. Commented Oct 4, 2011 at 15:30

2 Answers 2

1

Use this in your .htaccess file:

RewriteEngine on

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

Note the RewriteRule line in my code. There is no ? mark as you used. In RewriteCond you may use as many folders as you like and the mentioned folders have access. CodeIgniter can not access the resource from any folder that is not listed in RewriteCond here.

Sign up to request clarification or add additional context in comments.

1 Comment

yeah, it was an issue with my .htaccess. Thanks
0

You should also point your index method at the method you want to receive it. For example, if your class is "Registration" your index method should look like this:

public function index()
{
    this->registration();
}

Then do everything in the method called "registration." This will help keep things clear for other developers who might work on this code in the future.

Comments

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.