0

I have a simple html file (trying to start my way with valet) and in it i have a <link rel="stylesheet" href="./css/main.css">

Thing is, home.test/app doesn't show my styled htm. Chrome's inspector shows it tries to find the resouce file at home.test/css/main.css
While in home.test/app/ it is *not* styled. Ive been googling a cause/fix for some time and i cant wrap my head around it.

I have tried copying some of Statamic's valet driver configs without much success as a www.conf file. Also, ive seen some rewriting methods like

rewrite ^/(.*)/$ /$1 permanent;
rewrite ^/?(.*)$ /$1 break;

also without success

I'd like to access home.test/app and have it load all required files and if possible to redirect home.test/app/ to home.test/app removing the trailing slash

bronze
  • 79
  • 7

1 Answers1

0

The issue is likely to be down to the use of ./ in the href of the link. You're telling the server "go grab me the file from the folder /css/main.css from my current folder location.

Assuming your folder structure is:

   /index.php
   /css/main.css
   /app/index.php

When you're on the home page, you're saying go and retrieve home.test/css/main.css. However, when in the app folder, you're telling the server to go and retrieve home.test/app/css/main.css, rather than home.test/css/main.css.

The quickest solution will be to change the link to <link rel="stylesheet" href="/css/main.css"> (getting rid of the leading .). Otherwise you can use an absolute path.

  • well, its been a while, but if i remember correctly i was indeed trying to pull the css from the subfolder, not an abspath. i tried "file.css", "/file.css" and "./file.css" and they all disregard the folder they are in and pull from the root. i just re-read my issue and it seems i made a mistake, i meant that "While in home.test/app/ it is NOT styled" – bronze Nov 08 '19 at 16:23