简体   繁体   中英

Stylesheet not found when link is correct

I am trying to link my stylesheet to my php template for my website. I used the link: <link rel="stylesheet" type="text/css" href="{{app.request.basepath }}/App/views/templates/style.css">

Now, this works on my localhost server(I use MAMP), but when i upload the files to the web host I get the error:

Failed to load resource: the server responded with a status of 404 (Not Found)

The panel I have only seems to support up to 5.5, where as I use 5.6 on the local server. Could also be the issue.

And it also gives me a link, which is the exact link to the file, no misspelled or capitalized letters. The file I am trying to link the stylesheet to is in the same folder as the stylesheet. I am also rewriting the .htaccess file because I am using SlimPHP the file is:

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^ index.php [QSA,L]

I think that this might have something to do with it being unable to link but i am not fully sure. Thanks in advance for all of your help

Edit: I fixed my problem by linking my style sheet to the public file in my directory. From there, I could link any images by using CSS, but also I had to place them in the public directory

It was better to give us the online address.

But now you should check the converted address in your html codes.

You should press Ctrl+U in "Firefox" OR right click->View Page Source.

Then search for /App/views/templates/style.css"> then check the full address and change your main code !

授予style.css文件0777或0755权限以进行访问

This is how I route theme-specific stylesheets in Slim and Twig. First I create a new config variable, themes.path , that contains the actual filesystem path to my theme. Then I set up a route for css/theme.css :

$app->config([
    'themes.path'    =>  "path/to/themes"
]);

/* Render theme CSS */
$app->get('/css/theme.css', function () use ($app) {
    $app->response->headers->set("Content-Type", "text/css");
    $css_include = $app->config('themes.path') . "/myTheme/css/theme.css";
    $app->response->setBody(file_get_contents($css_include));
}    

To use the theme stylesheet in my template documents, I simply do:

<!-- Theme stylesheet -->
<link rel="stylesheet" href="{{site.uri.css}}theme.css" type="text/css" >

Where site.uri.css is a global template variable that contains the path to my (public) css directory. You can hardcode that part, if you prefer.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM