Welcome Guest, Not a member yet? Register   Sign In
redirect('/login') goes to /login.php
#1

[eluser]Nicolas Connault[/eluser]
Whenever I use the redirect() function of the URL helper, it incorrectly appends .php to the end of the path, no matter what path I put. For example:
Code:
redirect('/login');
goes to login.php (which doesn't exist).

Why is this happening? I have nothing besides the default entries in my config/routes.php file
#2

[eluser]nelson.wells[/eluser]
Have you tried

Code:
redirect('login');


instead? I don't know if it would make a difference, but it is the first thing I notice that I do differently in my apps. If that doesn't work, we can brainstorm about something else.
#3

[eluser]Nicolas Connault[/eluser]
No, that's not it, I tried that too and the result is the same Sad By the way, going manually to /login works fine, it's only the redirection that is incorrect. Thanks for your help, I'll keep trying different things while you rack your brain Smile

I'm also pasting my .htaccess file here just in case the problem lies there:

Code:
<IfModule mod_rewrite.c>
    RewriteEngine On
    RewriteBase /

    #Removes access to the system folder by users.
    #Additionally this will allow you to create a System.php controller,
    #previously this would not have been possible.
    #'system' can be replaced if you have renamed your system folder.
    RewriteCond %{REQUEST_URI} ^system.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    #When your application folder isn't in the system folder
    #This snippet prevents user access to the application folder
    #Submitted by: Fabdrol
    #Rename 'application' to your applications folder name.
    RewriteCond %{REQUEST_URI} ^application.*
    RewriteRule ^(.*)$ /index.php?/$1 [L]

    RewriteRule ^what's_on(.*)$ /whats_on$1

    #Checks to see if the user is attempting to access a valid file,
    #such as an image or css document, if this isn't true it sends the
    #request to index.php
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?/$1 [L]
</IfModule>
#4

[eluser]nelson.wells[/eluser]
The quickest way to figure out if the problem is with your .htaccess file is by removing your .htaccess file and seeing if your code works Wink
#5

[eluser]Nicolas Connault[/eluser]
I did this (renamed .htaccess to htaccess), and entered the full URL (using index.php), but I still get redirected to login.php Sad
#6

[eluser]nelson.wells[/eluser]
Could you post the controller you're calling this from (or a portion of it)?
#7

[eluser]Nicolas Connault[/eluser]
Code:
&lt;?php
class Enquiry extends Controller {
    function Enquiry() {
        parent::Controller();
        $this->load->library('form_validation');
        $this->load->model('enquiries/enquiry_model');
        if (!$this->login_model->check_session()) {
            redirect('/login');
        }
    }

    function index($enquiry_id=null) {
        $form_data = array();

        if (!empty($enquiry_id)) {
            $enquiry = $this->enquiry_model->get($enquiry_id);
        }

        // Unfinished code
    }
}
?&gt;
#8

[eluser]Nicolas Connault[/eluser]
OK, delving into the CI code I found the issue. It's a setting in config.php, called "url_suffix", and defaults to ".php". This appends .php to all URLs generated by CI! I changed that to an empty string, and voila! The redirection works perfectly!

Thanks for your help!
#9

[eluser]Rolly1971[/eluser]
not sure i understand why you had a problem with this.

every single uri is redirected to a *.php file.

for example:


example.com (whatever your test domain is)

redirects or loads the welcome.php controller.

so naturally if you put:

example.com/login

it would look for a controller of: login.php

why is that hard to understand?

i mean these things are made plainly clear in the documentation.

it is all in your routing.

i personally have not ever changed the default EXT config var.

But Yet, i still have fully working uri's. as i would assume 99% of the others here do.

the only stumbling block may be in the url rewrite for your server, which can be a pain in the ass for windows based servers. other than that i am not at all understanding why you had any issue at all with it.

set your config['base_url'] and config['index_page'] variables in config.php under application/config and you should not have any issues.

heaven forbid people simply just read the instructions.
#10

[eluser]Nicolas Connault[/eluser]
Instead of being rude and telling me that my problem is caused by my ignorance, you could just try to understand why the code behaves at it does. Your assumption that I haven't read "the instructions" proves to be false, anyway.

Quote:it is all in your routing.

Wrong. I haven't edited the config/routes.php file, it only has the 2 default entries. Maybe you can figure out what was going wrong if you're so well-versed in CI documentation!




Theme © iAndrew 2016 - Forum software by © MyBB