.htaccess文件被解释为脚本,但转移时使用了MIME类型text/html。

3

在我添加以下行到我的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=...

那么,请问如何解决这个问题呢?

2个回答

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>

0

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

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

这将确保RewriteRule仅在文件不存在时触发(因此,例如css文件的重写规则将不再触发)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接