Search code examples
html.htaccess

htaccess MIME type css read as text/html


Before you reference similar questions: I did actually do research yet no post solved my issue.

I literally have the most basic code you can imagine yet one of the most basic things won't work. The CSS file is interpreted as text/html while I need it to be a read as a stylesheet. This is due to my .htaccess file even though I explicitly added the AddType thing.

Here's my HTML:

  <!doctype html>
  <html lang="en">
    <head>
        <meta charset="UTF-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <title>EASY-Online</title>
        <link href="./css/bootstrap.min.css" type="text/css"/>
    </head>
    <body>
        <div class="alert alert-warning">
            test
        </div>
    </body>
  </html>

My htaccess:

RewriteEngine On
RewriteBase /
AddType text/css .css
RewriteCond %(REQUEST_FILENAME} !-d
RewriteCond %(REQUEST_FILENAME} !-f
RewriteCond %(REQUEST_FILENAME} !-l

RewriteRule ^(.*)$ index.php?url=$1 [QSA,L,T=text/css]

Solution

  • After some more research I found this to fix my issue:

    RewriteCond %{REQUEST_URI} !\.(?:css|js|jpe?g|gif|png)$ [NC]
    

    I added this directly above the RewriteRule. Apparently this allows the described extentions to be reachable by navigating to them instead of redirecting.