用MIME类型text/html传输的样式表 [英] Stylesheet transferred with MIME type text/html

查看:110
本文介绍了用MIME类型text/html传输的样式表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您将通过以下消息了解我的问题

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".

我在Win7 64位上使用xampp.

I'm using xampp on Win7 64bit.

使用以下MVC构建应用. 我没有使用任何框架,只是从头开始构建以获得更好的理解. Apache重写已启用,并且正在使用.htaccess以便仅将入口限制为index.php.

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]

索引php进行一些初始化,并触发下面给出的主控制器.

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);          
  }
}

?>

如果遵循,则再创建一个子控制器.确切的工作由子控制器和一个加载的模板文件确定,该模板文件由html组成,但具有php扩展名.下面给出了从上载子控制器加载的模板文件(按预期方式工作).

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>

页面加载后,按Ctrl-U浏览页面代码,然后单击"css/style.css",如下所示,浏览器将在新页面中加载css文件.这是我所期待的,而且正在不断发展.

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 heppening.

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

坏消息从现在开始.

当我的主控制器加载子控制器用户(用于登录,注销等)并且加载了登录模板(正好在下面给出)时,我得到了所有我期望的html元素,但未应用css方向.相反,我得到的消息显示在页面顶部.

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>

再次检查代码并单击css/style.css,将加载一个新的空白页,并调用服务器处理的输入为css/style.css的服务器(逻辑类型为text/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).

我正在四处搜寻,但找不到任何解决方案. Apache已正确配置(或未正确配置),因为它可以很好地用于上载部分. 我在.htaccess文件中添加了以下行,但没有运气.

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

有什么想法吗?

推荐答案

要解决CSS问题,请检查bin/apache/apache version/文件夹中的/conf/mime.types文件.被发现.然后,您想这次搜索文件扩展名,以供以后在httpd.config文件中使用,以使用AddType和AddHandler指令配置模块. httpd.config文件看起来像这样

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 

取决于mime.types设置为哪种媒体类型

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"

也可以在CSS文件中使用它

Also use this in the CSS file

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

只需将样式表链接到php文件:)

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

这篇关于用MIME类型text/html传输的样式表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆