use relative url instead of full: https://example.com/route/item -> /route/item |
Hi there,
is there a way to use a relative url's instead of full url which includes protocol, host, ... eg: PHP Code: echo base_url( 'project/route/item' ); // to produce "/project/route/item", instead of "https://example.com/project/route/item"
These should help you out.
CodeIgniter 4 User Guide - url_to() CodeIgniter 4 User Guide - route_to() CodeIgniter 4 User Guide - Named Routes What did you Try? What did you Get? What did you Expect?
Joined CodeIgniter Community 2009. ( Skype: insitfx )
Thank you for reply,
but my question was not about the generating a link, but about the way link is generated. If i replace all links with a static once, the codeigniter still wont work correctly and force me jump to the url with prefix defined in a app.baseURL. All of the helper functions and codeigniter core itself will provide links with app.baseURL in prefix. But I cant specify, let say PHP Code: $baseURL ="/project/"; To make it short, I would like to see relative path generated by all those functions (base_url, url_to, .. etc ) and codeigniter core itself rather then full url path to all generated links. Code: ~ ~ ~ 8< App.php >8 ~ ~ ~ How to get rid of "https://example.com". Thanks.
There is no such a way.
You need to customize the functions/framework. These are basic functions that are used in the framework, so it is better to add new functions to return relative path values, and use them in your app.
@nerozero It is strange that base_url() returns relative paths. It is a function for returning the base URL.
If you want PHP Code: echo base_url('project/route/item'); to produce "/project/route/item", why don't you write it as following? PHP Code: echo '/project/route/item';
@kenjis
Here is some of the situation,
If there is already recommended approach to generate result url, such as "url_to(), base_url(), route_to()...", will be nice to have some flexibility built-in into framework. From my perspective a better approach will be - having config variables like "$web_root" and "$allowed_hosts = [ "example.com", "example2.com","www.example2.com"]
Maybe if you create a function to get just the path from base_url(), it seems like it would meet your needs.
CodeIgniter is an open source framework, so you could contribute the new function. |
Welcome Guest, Not a member yet? Register Sign In |