subdomain is lost on redirect()->to() |
Hello!
I love CI4, so far so good! ![]() I set up my site to handle subdomains as languages, e.g.: mydomain.com de.mydomain.com fr.mydomain.com The problem is when I redirect, it loses the subdomain, for example : I'm on the page de.mydomain.com I send a form, the controller redirects with this code: Code: return redirect()->to('/search'); I arrive to mydomain.com/search instead of de.mydomain.com/search
You have to use full URL here. Otherwise CI will use baseURL from App config file as default domain.
michalsn.dev - mostly about CodeIgniter
Have you tried using
PHP Code: current_url() which will return the full url (including segments that you can strip out) in your redirect statement? So it could possibly look like this: PHP Code: $url = str_replace("/unwanted/segments", "/search", current_url());
Thanks for the replies.
Kick: current_url() leaves the subdomain out as well. I managed to solve it using the full path like this: PHP Code: return redirect()->to('https://' . $_SERVER['HTTP_HOST'] . '/search'); However, I think the default behavior of the to() function should be to use the full URL, including the subdomain. And maybe put a second optional boolean argument if you want to redirect to the domain without the subdomain part, e.g.: PHP Code: // you are on https://de.mydomain.com/
You can define baseURL property in App config (Config/App) like this:
PHP Code: public function __construct()
Thanks! It's a nice workaround and I don't have to rewrite all the to() and back() functions! BTW I tracked down the issue to current_url() function, that's where the subdomain goes missing.
(05-18-2020, 04:33 AM)ARAmiss Wrote: You can define baseURL property in App config (Config/App) like this: |
Welcome Guest, Not a member yet? Register Sign In |