I'm trying to run a localhost version of a website and the stylesheet for the site in inexplicably inaccessible to the browser.

Some Basics:

  • OS: Windows
  • Browser: Chrome (have also tried Edge)
  • Editing environement: Eclipse
  • XAMPP: v3.2.4

This is how I'm calling the CSS file.

<link href='/style.css' rel='stylesheet' type='text/css' />

I'm updating some PHP on a site that is fairly old, the site was using PHP 5.5.9 and we want to update it to the latest PHP (off the top of my head it's 7.2.3). In doing this I want to modify the site code locally before changes are applied to our server. The server is Linux based so that is one fundamental dependency that is different from my local environment.

A problem that I've run into is that the CSS file returns either error 404 or error 403 if the location https://localhost/style.css is put into the chrome browser. It seems that this happens if the path to the CSS file is wrong or the permissions to the file are not readable. I've tried converting the path of the CSS to an absolute path, I've checked the permissions and the system has all the read capability it needs.

I thought the problem might have been with the actual path to the CSS, but it's in the same location as the all the PHP files which are loading in just fine, whether using relative root location or document root. Note, the document root is now a subfolder with the HTML docs that contains all the website files for the page.

And please note that I've not modified this CSS file at all. It's the same as the one running on the live site.

  • 2
    Does this website have an .htaccess file that might be rewriting URLs? Also, I know you are on Windows, but if you somehow can run Curl from the command line run this command to see how the URL might be redirected or resolved: curl -I http://localhost/style.css. Additionally I would recommend using Firefox for debugging since it’s not as forceful in caching data—or enforcing HTTPS—as other browsers such as Chrome. – Giacomo1968 Jun 26 '19 at 20:32
  • 2
    Is the CSS file really on the root folder? Or in the same folder as the HTML / PHP file? In that case the HREF should be ./style.css or just style.css – Shifty Jun 26 '19 at 20:45
  • On the page that is failing press F12 in your browser to see the developers window and look at the console tab to see if there are any errors. – Dave Jun 27 '19 at 11:39
  • For the curl command the output was as follows : HTTP/1.1 404 Not Found Date: Thu, 27 Jun 2019 13:19:10 GMT Server: Apache/2.4.39 (Win64) OpenSSL/1.1.1c PHP/7.3.6 Vary: accept-language,accept-charset Accept-Ranges: bytes Content-Type: text/html; charset=utf-8 Content-Language: en – mockforce Jun 27 '19 at 13:20
  • I also tried curl -I localhost/rebat.css. and got : curl: (77) schannel: next InitializeSecurityContext failed: SEC_E_UNTRUSTED_ROOT (0x80090325) - The certificate chain was issued by an authority that is not trusted. – mockforce Jun 27 '19 at 13:20

Giacomo1968’s comment gets the credit for the fix. the line RewriteRule ^style.css$ /style-css.php [L] was removed from .htaccess.

I'm still vague on what that line was for, there was no style-css.php file in the project root. This allowed the CSS to be viewed.

Thanks everyone.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.