2

As you would have already understood my problem by the messages below

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/EcoVis/user/css/style.css". login:5
Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/EcoVis/user/css/navigation.css".

I'm using xampp on Win7 64bit.

Building an app using following MVC. I'm not using any framework ,just building from ground in order to get a better understanding. Apache rewrite is on and .htaccess is in use in order to restrict entry only to index.php.

##  Can be commented out if causes errors, see notes above.
Options +FollowSymLinks

#Folder indexing
Options -Indexes

#  mod_rewrite in use

RewriteEngine On

########## Begin - Rewrite rules to block out some common exploits
## If you experience problems on your site block out the operations listed below
#
## Deny access to extension xml files (uncomment out to activate)
#<Files ~ "\.xml$">
    #Order allow,deny
    #Deny from all
    #Satisfy all
#</Files>

#Secure access to php files except from index.php,proxy_get.php,proxy_post.php
<FilesMatch "\.php$">
    Order Allow,Deny
    Deny from all
</FilesMatch>
#Allow access only to index files of each folder.
<FilesMatch "^(index)\.php$">
    Order Allow,Deny
    Allow from all
</FilesMatch>


RewriteCond %{QUERY_STRING} mosConfig_[a-zA-Z_]{1,21}(=|\%3D) [OR]
# Block out any script trying to base64_encode crap to send via URL
RewriteCond %{QUERY_STRING} base64_encode.*\(.*\) [OR]
# Block out any script that includes a <script> tag in URL
RewriteCond %{QUERY_STRING} (\<|%3C).*script.*(\>|%3E) [NC,OR]
# Block out any script trying to set a PHP GLOBALS variable via URL
RewriteCond %{QUERY_STRING} GLOBALS(=|\[|\%[0-9A-Z]{0,2}) [OR]
# Block out any script trying to modify a _REQUEST variable via URL
RewriteCond %{QUERY_STRING} _REQUEST(=|\[|\%[0-9A-Z]{0,2})
# Send all blocked request to homepage with 403 Forbidden error!
RewriteRule ^(.*)$ index.php [F,L]


#  Uncomment following line if your webserver's URL
#  is not directly related to physical file paths.

# RewriteBase /


########## Core sef Section
# Index.php is the only gateway to the webapp
# If the request is for a real directory (one that exists on the server), index.php isn't served.
RewriteCond %{REQUEST_FILENAME} !-f
#If the request is for a file that exists already on the server, index.php isn't served.
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php?rt=$1 [L,QSA]

Index php makes some initialization and fires the main controller given below.

<?php

/**
 * Controller decides where the next step will be.
 * Web server's RewriteEngine On is needed.
 * the rt from _GET['rt'] is defined in .htaccess
 *
 */

class controller extends baseController {
  
  public function load()
  { 
      /*  get the route from the url  */
      $route = (empty($_GET['rt'])) ? '' : $_GET['rt'];

      if (empty($route)) 
      {
        $controller = 'main';
        $action = NULL;
      } 
      else 
      {
        /*  decide the route  */
        $parts = explode('/', $route);
        switch ($parts[0]) {
          case 'uploaddata':
            $controller = 'uploaddata';
            $action = $parts[1];
            break;
          case 'exportdata':            
            break;
          case 'user':
            $controller = 'user';
            $action = $parts[1];
            break;            
          case 'about':
            break;
          default:
            break;
        } 
      }
      
          require_once __SITE_PATH . '/controller/controller_' . $controller . '.class.php';
          $controller = 'controller_' . $controller;
          $c = new $controller($this->registry);
          $c->load($action);          
  }
}

?>

Then a sub-controller if followed. The exact job is determined from the subcontroller and a template file which is loaded which consists of html but having a php extension. The template file that is loaded from the upload sub-controller (which is working as meant to be) is given below.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <title>Visualization of Economic Data</title>
      <link rel="shortcut icon" href="favicon.ico"/>
      <link href="css/style.css" rel="stylesheet" type="text/css" media="screen"/>
      <link href="css/navigation.css" rel="stylesheet" type="text/css" media="screen"/>
      <script type="text/javascript" src="scripts/jquery-1.9.1.min.js"></script>      
      <script type="text/javascript" src="scripts/uploaddata.js"></script>      
    </head>
    <body>
      <div id="main">
        <?php
          include(__SITE_PATH . '/views/header.php');
          include(__SITE_PATH . '/views/uploaddata.php');
          include(__SITE_PATH . '/views/footer.php');
        ?>
      </div>
    </body>
</html>

After the page loads and pressing Ctrl-U to have a look in page code and clicking on the "css/style.css", as shown below, the browser loads in a new page the css file. This is what I was expecting to happen and it is happening.

  <link href="css/style.css" rel="stylesheet" type="text/css" media="screen"/>

The bad news start now.

When my main controller loads the subcontroller user (used for login, logout etc) and the login template (given exactly below) is loaded I'm getting all the html elements that I expect but css directions are not applied. Instead I'm getting the messages shown at the top of the page.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
      <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
      <title>Visualization of Economic Data</title>
      <link rel="shortcut icon" href="favicon.ico"/>
      <link href="css/style.css" rel="stylesheet" type="text/css" media="screen"/>
      <link href="css/navigation.css" rel="stylesheet" type="text/css" media="screen"/>
    </head>
    <body>
      <div id="main">
        <?php
          include(__SITE_PATH . '/views/header.php');
          include(__SITE_PATH . '/views/login.php');
          include(__SITE_PATH . '/views/footer.php');
        ?>
      </div>
    </body>
</html>

Checking again code and clicking on css/style.css a new blank page loads and a call is made to the server having as input the css/style.css which is processed by the controller (logical as type is text/html).

I'm googling around but I can't find any solution. Apache is configured correctly (or not) as it works nice for the upload part. I added the following line in .htaccess file but with no luck.

AddType text/css .css

Any ideas of what is going on?

Pavlos Papanikolaou
  • 593
  • 2
  • 7
  • 23
  • :hope this would help you :) http://stackoverflow.com/questions/3467404/chrome-says-resource-interpreted-as-script-but-transferred-with-mime-type-text – dreamweiver Apr 12 '13 at 10:45

4 Answers4

5

Check your /etc/apache2/apache2.conf If there are any SetHandler application/x-httpd-php line, try to comment it and then reload your apache by $ sudo system apache2 reload

Let us know if the problem is still there.

You can also check your other sites (/etc/apache2/sites-enabled/*.conf) to make sure that none of them have a similar line.

Kunc
  • 102
  • 2
  • 9
Sid
  • 4,302
  • 3
  • 26
  • 27
  • I just ran into this problem myself, and commenting out `SetHandler application/x-httpd-php` in `apache2.conf` solved the issue. If someone can explain why, it would be greatly appreciated. – pusle Jun 08 '22 at 21:08
  • After upgrading Ubuntu to 22.04 I ran into this problem. MANY hours later I come across this solution. THANK YOU! – maleman Apr 21 '23 at 12:05
2

To fix this issue with the CSS problem check the /conf/mime.types file in the folder found in the bin/apache/apache version/ folder where it is found . You want to then search for the file extension name in this time to use later in the httpd.config file to configure the module using the AddType and AddHandler directive . The httpd.config file would look something like this

AddType text/CSS .css 
AddHandler text/css .css 

Depending on what media type the mime.types is set to

Also the path should have a "/" like this

"/styles/style.css" or "/style.css"

Also use this in the CSS file

<?php header("Content-Type:text/css; charset: UTF-8"); ?>

And just link the style sheet to the php file :)

1

If after adding "AddType text/css .css" to both httpd.conf and root .htaccess and reloading your apache, another likelihood I would attribute the error to would be the path - paths are case sensitive.

Do also try absolute path from the root directory, i.e. instead of "css/styles.css" use "/css/styles.css"

Rich
  • 3,156
  • 3
  • 19
  • 29
George
  • 6,006
  • 6
  • 48
  • 68
0

My Error:

Resource interpreted as Stylesheet but transferred with MIME type text/plain: ""

FIX

1> Add at httpd.conf

AddType text/CSS .css 
AddHandler text/css .css 

2> Reset apache

Tính Ngô Quang
  • 4,400
  • 1
  • 33
  • 33