Welcome Guest, Not a member yet? Register   Sign In
Relative URLs, or Absolute URLs?
#11

[eluser]Phil Sturgeon[/eluser]
Not a great plan to overwrite the base_url method. Thats gonna have a bunch of nasty effects that you really dont want to deal with.

Why not just add your own function to the url helper and make base_path() or just make your own config variable thats autoloaded. Much easier to add a new method than change an important part of the framework.
#12

[eluser]jayapalchandran[/eluser]
Yeah, as stated by the previous reply....
$config['rel_url'] = '/folder/' // if you are running from localhost and just '/' for the server but still if you are running from a sub folder then '/folder/' would be the relative url and add a function like the samd as function base_url for rel_url like function rel_url()
Code:
if ( ! function_exists('base_url'))
{
    function base_url()
    {
        $CI =& get_instance();
        return $CI->config->slash_item('base_url');
    }
}

if ( ! function_exists('rel_url'))
{
    function rel_url()
    {
        $CI =& get_instance();
        return $CI->config->slash_item('rel_url');
    }
}
in the url_helper.php file...


BUT...
#13

[eluser]jayapalchandran[/eluser]
BUT...
as i have been reading the complete page i found that a person has stated that there will be difference between accessing a url as relative and absolute from the same site.

like images/logo.gif and sitename.com/images/logo.gif

my understanding was that what ever it is the browser has to create a connection to the server to fetch that file using threads so that images show up asynchronously...

may be instead of creating a new socket every time the browser can just open one connection and can send multiple requests with the one open connection if the request is relative

and if the request is absolute then for each abs url the browser has to create a socket and that adds up to overhead...

This is my idea and i request users to post their thought so that every one could have a clear idea.
#14

[eluser]jayapalchandran[/eluser]
And i faced another problem by using absolute url is with flash and ajax.
and ajax request with www and non www.
if you have set baseurl as http://sitename.com and if you are accessing scripts using ajax then you might face this problem

consider that the users is accessing the page using http://sitename.com and in your config you have did it like baseurl = 'http://sitename.com . then there wont be a problem because there is no www in the browser url and also in the ajax request...

but if users try to access the page as http://www.sitename.com then the absolute url for ajax will not work and it will throw Permission Denied error because the actual url is http://www.sitename and the now ajax url is http://site which are different and hence an error is thrown.

the same error will throw up for flash or other controls i hope.
so even in flash if you are displaying images using dynamically generated xml then you should access the url as relative and not absolute... so /folder/xmloutput.php would be appropriate...
#15

[eluser]jayapalchandran[/eluser]
to circumvent these things better redirect non www to www using htaccess or redirect www to non www urls...

like the following and use absolute urls...

RewriteCond %{HTTP_HOST} ^www.site.com [NC]
RewriteRule ^(.*)$ http:/site.com/$1 [L,R=301]

my example is removing www from url.
if you are hosting in a subfolder then add it to the rule.

and BTW anytime anybody if there is objection then please post it so that all can update their mind if there is any corrections.
#16

[eluser]saidai jagan[/eluser]
Hi jayapalchandran happy to c u. vaazha Tamil.




Theme © iAndrew 2016 - Forum software by © MyBB