• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Redirect issue

#1
Hello,

I am working on a new project with Codeigniter 4.0 beta 4. I set the URL in the configuration file:

PHP Code:
public $baseURL 'http://localhost/mysite/'

If I now use a redirect, the URL will be redirected to an incorrect URL.

PHP Code:
return redirect()->to('/admin'); 

This call redirects to the following URL:

http://localhost/admin

I'd like someone to help me with this problem.

Thanks
Tom
Reply

#2
(07-25-2019, 11:18 PM)SirTom Wrote: Hello,

I am working on a new project with Codeigniter 4.0 beta 4. I set the URL in the configuration file:

PHP Code:
public $baseURL 'http://localhost/mysite/'

If I now use a redirect, the URL will be redirected to an incorrect URL.

PHP Code:
return redirect()->to('/admin'); 

This call redirects to the following URL:

http://localhost/admin

I'd like someone to help me with this problem.

Thanks
Tom

I assume that in this function you should specify the full path to the page including the 1st segment "mysite":
Code:
return redirect()->to('mysite/admin');

and in order to be able to direct to the abbreviated url addresses you need to name each of your router in this way:
Code:
$routes->add('{locale}/admin', 'Users::profile', ['as' => 'my_route']);

and call the function:
Code:
redirect()->route('my_route');
or just
redirect('my_route');
I would change this world, but God doesn't give me the source.
Reply

#3
Thank you. This solution works, BUT it seems to be a bug.

I have called the following URL: http://localhost/mySite/myController/myFunction

with


PHP Code:
public $baseURL 'http://localhost/mySite/'



Now i call a redirect with:


PHP Code:
return redirect()->back() 


I will be redirected to the following URL: http://localhost/myController/myFunction

The URI-Element /mySite/ is missing.
Reply

#4
(07-26-2019, 03:04 AM)SirTom Wrote: Thank you. This solution works, BUT it seems to be a bug.

I have called the following URL: http://localhost/mySite/myController/myFunction

with


PHP Code:
public $baseURL 'http://localhost/mySite/'



Now i call a redirect with:


PHP Code:
return redirect()->back() 


I will be redirected to the following URL: http://localhost/myController/myFunction

The URI-Element /mySite/ is missing.

I think you have in the apache server settings is not installed option "root document",
go to the settings in file httpd.conf and set it
Code:
DocumetRoot = "mySite/public"
,
then you can redirect without substitution segment of "mySite",
just typing in your browser's address bar as

Code:
http://localhost/myController/myFunction
and so on
I would change this world, but God doesn't give me the source.
Reply

#5
I have the same issue. It looks like CI4 cannot be installed in a subdirectory without running in redirect problems. I also think there's a bug somewhere because not all web apps will have their own domain.

I have the following config on a Windows 10 PC for local development and testing, using XAMP and CodeIgniter 4.0.0 beta 4 installed in a directory named ci4:

In Apache config :
Code:
Alias /ci4 "/xampp/htdocs/alain/ci4/public"

In ci4/public/.htaccess:
Code:
RewriteBase /ci4/

In ci4/app/Config/App.php:
PHP Code:
public $baseURL 'http://localhost:8080/ci4/';
public 
$indexPage ''

If I use site_url('login') or anchor('login'), it generates a valid URL to http://localhost:8080/ci4/login, but if I use route_to('login') or redirect()->back()->withInput()->with('error', lang('Auth.badAttempt')) it redirect to http://localhost:8080/login and gives a 404 error.

I got those errors while testing https://github.com/lonnieezell/myth-auth
Test your translation files with Translation Tester
Reply

#6
When did you get his Myth Auth because he updated about a month ago for the
new soft deletes etc;
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#7
I' am running XAMPP on Windows 10 Pro x64 1903

But I use vhost for mine.

Edit C:\xampp\apache\conf\extra\httpd-vhost.conf
Make sure that this is not remarked out with a #: NameVirtualHost *:80

Add this line to the bottom: Include "conf/extra/vhosts/*.conf"

Create a new file called: C:\xampp\apache\conf\extra\vhosts\vhosts.conf

Add this to the file and make copies of it when needed.
Edit to your own setup.

Code:
#--------------------------------------------------------------
#
#--------------------------------------------------------------

#--------------------------------------------------------------
# HTTP:
#--------------------------------------------------------------
#<VirtualHost *:80>
#    DocumentRoot "C:/xampp/htdocs/myproject/public_html"
#    ServerName .local
#    ServerAlias .local
#    <Directory "C:/xampp/htdocs/myproject/public_html">
#        Order allow,deny
#        Allow from all
#        AllowOverride All
#        Require all granted
#    </Directory>
#</VirtualHost>

#--------------------------------------------------------------
# HTTPS:
#--------------------------------------------------------------
#<VirtualHost *:443>
#    DocumentRoot "C:/xampp/htdocs/myproject/public_html"
#    ServerName .local
#    ServerAlias .local
#    SSLEngine on
#    SSLCertificateFile "conf/ssl.crt/server.crt"
#    SSLCertificateKeyFile "conf/ssl.key/server.key"
#    <Directory "C:/xampp/htdocs/myproject/public_html">
#        Options All
#        AllowOverride All
#        Require all granted
#    </Directory>
#</VirtualHost>

#--------------------------------------------------------------

Now all you have to do is add the url to the Windows hosts file.

Edit: C:\Windows\System32\drivers\etc\hosts

you can edit it with notepad with administrator rights.

Add:


Code:
127.0.0.1    localhost
::1        localhost

# Bootstrap HTML Development Server.
127.0.0.1    bs4.local

# PHP Development Servers.
127.0.0.1    test.local

#-- CI 3
#127.0.0.1    ci.local
 
Reboot your server and you are good to go.
You can now use a base_url like https://ci3.local/

The vhost file will map everything out for you.

Note: this is for testing on local machine only!
What did you Try? What did you Get? What did you Expect?

Joined CodeIgniter Community 2009.  ( Skype: insitfx )
Reply

#8
(08-02-2019, 02:11 PM)InsiteFX Wrote: When did you get his Myth Auth because he updated about a month ago for the
new soft deletes etc;

The same day I replied.
Test your translation files with Translation Tester
Reply

#9
(08-02-2019, 02:41 PM)InsiteFX Wrote: I' am running XAMPP on Windows 10 Pro x64 1903

But I use vhost for mine.


Reboot your server and you are good to go.
You can now use a base_url like https://ci3.local/

The vhost file will map everything out for you.

Note: this is for testing on local machine only!

Yes I know I can set up a virtual host, but that's not the point. It should work when installed in a sub directory. The framework should always use the configuration options to generate the URL's (baseURL and indexPage) and never assume it can be accessed at the root of the domain where it's installed or that you will use mod_rewrite to remove index.php.
Test your translation files with Translation Tester
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.