Welcome Guest, Not a member yet? Register   Sign In
Relative link to CSS
#14

[eluser]ntheorist[/eluser]
[quote author="tokyotech" date="1247178984"]
I prefer not to use the base_url() thing because that just prints out www.example.com. Even if I changed it to localhost, it would be a hassle to change
[/quote]

set these settings in your config/config.php

Code:
$config['base_url'] = ((isset($_SERVER['HTTPS']) && $_SERVER['HTTPS'] == "on") ? "https" : "http");
$config['base_url'] .= "://".$_SERVER['HTTP_HOST'];
$config['base_url'] .= str_replace(basename($_SERVER['SCRIPT_NAME']),"",$_SERVER['SCRIPT_NAME']);

You shouldn't have to worry about ever editing that again. I know how much a pain moving from local to test to live and back again can be. Also, for the database i usually create three groups of setting for each environment. $db['local'], $db['test'], $db['live'], which you could set based on the info returned by the new automatic base_url();

Also, i'm not sure if this affects css/js links, but look into the html <base> tag. It tells every (relative) link on your page to be relative to that url. Its good because its supported by almost every browser and as easy as
Code:
echo '<base href="'.base_url().'"/>';
The downfall with it tho is that it will break your page anchors (#'s) unless they are either made absolute (using current_url() perhaps?) or modified by javascript to point to the page . (jQuery could prolly also provide a solution in less than 5 lines of code)

_n


Messages In This Thread
Relative link to CSS - by El Forum - 07-08-2009, 06:48 PM
Relative link to CSS - by El Forum - 07-08-2009, 07:05 PM
Relative link to CSS - by El Forum - 07-08-2009, 07:35 PM
Relative link to CSS - by El Forum - 07-08-2009, 08:03 PM
Relative link to CSS - by El Forum - 07-08-2009, 08:30 PM
Relative link to CSS - by El Forum - 07-08-2009, 09:14 PM
Relative link to CSS - by El Forum - 07-09-2009, 06:20 AM
Relative link to CSS - by El Forum - 07-09-2009, 11:36 AM
Relative link to CSS - by El Forum - 07-09-2009, 11:52 AM
Relative link to CSS - by El Forum - 07-09-2009, 05:51 PM
Relative link to CSS - by El Forum - 07-09-2009, 07:27 PM
Relative link to CSS - by El Forum - 07-09-2009, 07:30 PM
Relative link to CSS - by El Forum - 07-09-2009, 07:44 PM
Relative link to CSS - by El Forum - 07-09-2009, 10:28 PM
Relative link to CSS - by El Forum - 07-10-2009, 12:15 PM
Relative link to CSS - by El Forum - 07-10-2009, 12:21 PM
Relative link to CSS - by El Forum - 07-10-2009, 01:20 PM
Relative link to CSS - by El Forum - 07-10-2009, 01:39 PM
Relative link to CSS - by El Forum - 07-10-2009, 02:26 PM
Relative link to CSS - by El Forum - 07-10-2009, 02:44 PM
Relative link to CSS - by El Forum - 07-10-2009, 02:48 PM
Relative link to CSS - by El Forum - 07-10-2009, 03:20 PM
Relative link to CSS - by El Forum - 07-10-2009, 03:43 PM
Relative link to CSS - by El Forum - 07-10-2009, 04:22 PM
Relative link to CSS - by El Forum - 07-10-2009, 04:23 PM
Relative link to CSS - by El Forum - 07-10-2009, 04:52 PM
Relative link to CSS - by El Forum - 07-10-2009, 05:54 PM
Relative link to CSS - by El Forum - 07-10-2009, 06:43 PM
Relative link to CSS - by El Forum - 07-10-2009, 07:15 PM



Theme © iAndrew 2016 - Forum software by © MyBB