Welcome Guest, Not a member yet? Register   Sign In
Two backslash in url in virtualhost
#1

Hi , i use xammp to testing my project in locale with windows using the guide of first response of this tread : 
https://stackoverflow.com/questions/2775...pp-windows

in C:\Windows\System32\drivers\etc i do :
Code:
127.0.0.1  my_project
and in my .env
Code:
app.baseURL = 'http://my_project'
this is my filter of admin not logged :
Code:
    public function before(RequestInterface $request, $params = null)
    {
        // if no user is logged in then send them to the login form
        if (!session()->get('admin_id'))
        {           
            session()->set('redirect_url', current_url());
           
            return redirect()->to(base_url().'/admin/login');
        }
    }
if i try to see http://my_project/admin

the system redirect me to the login (ok) but with this link :
http://my_project//admin/login (with 2 / )
Why ?
Reply
#2

Because the baseURL should end with a slash (/).

Try: base_url('admin/login');
Reply
#3

(08-02-2023, 11:29 PM)kenjis Wrote: Because the baseURL should end with a slash (/).

Try: base_url('admin/login');

same problem with base_url ending with / on hosting in subfolder
Reply
#4

remove the forward slash before admin in your redirect:
"return redirect()->to(base_url() . '/admin/login');" <- wrong
"return redirect()->to(base_url() . 'admin/login');" <- correct
Shortcode Κατασκευή Eshop + Δημιουργία Ιστοσελίδων 
Athens Greece 
Reply
#5

What Kenji means is that your base_url is probably http://my_project/
including the backslash.
To go to the admin page, you shouldn't use:
Code:
return redirect()->to(base_url().'/admin/login');

but:
Code:
return redirect()->to(base_url().'admin/login');
without a backslash in front of admin/login
Reply
#6

Why are you using merge instead of passing a parameter to a function? It's so annoying.
Simple CI 4 project for beginners codeigniter-expenses ( topic )
Reply




Theme © iAndrew 2016 - Forum software by © MyBB