There are multiple ways to set the URLs to your files. I don't know if I got your folder structure right. But let's suppose that your web root is set to
/var/www/craft-portfolio/public/
,
your CSS folder is
/var/www/craft-portfolio/public/css/
and your Craft folder (actually not relevant) is
/var/www/craft-portfolio/craft/
.
Root-relative URL
Root-relative URLs start with a /
character.
<link rel="stylesheet" href="/css/build.css" />
If you are using multiple environments, the path from the web root to your file has to be the same on each environment.
Something like this won't work with root-relative URLs:
http://mysite.com/css/build.css
http://192.168.178.20/projects/mysite/css/build.css
Absolute URL
Add the complete URL of the CSS file to the link tag:
<link rel="stylesheet" href="http://mysite.com/css/build.css" />
You can also use Craft's global siteUrl
variable. To do that define the site's URL (http://mysite.com/
) in Settings → General in the Control Panel and add the variable to your tag:
<link rel="stylesheet" href="{{ siteUrl }}css/build.css" />
If you want to use the variable in a multi-environment setup, define it in your general.php
file (this overrides the CP settings):
return array(
'192.168.178.20' => array(
'siteUrl' => 'http://192.168.178.20/projects/mysite/',
),
'craft.dev' => array(
'siteUrl' => 'http://craft.dev/',
),
'mysite.com' => array(
'siteUrl' => 'http://mysite.com/',
)
);
Just be careful if you want to use this on a multilingual Craft site. If you have multiple locales configured, siteUrl
will be set to each locale's site URL, which might point to different folders.
You can avoid this by setting a custom variable (eg. baseUrl
) in your general.php
file:
'environmentVariables' => array(
'baseUrl' => 'http://example.dev/',
)
and then use the absolute URL like so:
<link rel="stylesheet" href="{{ craft.config.environmentVariables.baseUrl }}css/build.css" />