【问题标题】:.htaccess Resource interpreted as Script but transferred with MIME type text/html.htaccess 资源解释为脚本,但使用 MIME 类型 text/html 传输
【发布时间】:2014-12-01 17:05:34
【问题描述】:

将此行添加到我的 htaccess 后,我遇到了一个大问题:

RewriteRule ([a-z]+)/   index.php?p=$1 [L]

我有这样的错误:

Resource interpreted as Stylesheet but transferred with MIME type text/html: "http://localhost/media/css/lvnr.min.css".
Resource interpreted as Script but transferred with MIME type text/html: "http://localhost/media/js/bootstrap.min.js".

我认为问题在于我的 htaccess 尝试将所有链接 media/... 重定向到 index.php?p= ...

请问如何解决

【问题讨论】:

    标签: php apache .htaccess rewrite


    【解决方案1】:

    您应该在 RewriteRule 之前添加类似这样的内容:

    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    

    这将确保 RewriteRule 仅在文件不存在时才会触发(例如,对于 css 文件,rewriterule 将不再触发)。

    【讨论】:

      【解决方案2】:

      正如您已经假设的那样,您的规则与您的媒体/... 您可能希望您的正则表达式以 $:

      结尾
      RewriteRule ([a-z]+)/$   index.php?p=$1 [L]
      

      编辑:您也可能有兴趣从 CDN 加载公共库(如 boostrap)以获得更好的性能:

      <script src="//maxcdn.bootstrapcdn.com/bootstrap/3.2.0/js/bootstrap.min.js"></script>
      

      【讨论】:

        猜你喜欢
        • 2014-07-12
        • 2011-07-18
        • 2014-07-15
        • 2012-06-18
        • 2012-11-23
        • 1970-01-01
        • 2017-02-23
        • 2018-01-23
        • 1970-01-01
        相关资源
        最近更新 更多