.htaccess Resource interpreted as Script but transferred with MIME type text/html

爱⌒轻易说出口 提交于 2020-01-02 07:16:26

问题


I've a big problem after I add this line into my htaccess:

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

I have error like that:

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

I think that the problem is that my htaccess try to redirect all the link media/... to index.php?p= ...

So how to fix it please


回答1:


As you already assumed, your rule matches your media/... You probably want your regex to end on $:

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

Edit: Also you might be interested in loading public libraries like boostrap from a CDN for better performance:

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



回答2:


You should add something like this before your RewriteRule:

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

This will make sure that the RewriteRule will only trigger if the file does not exist (so the rewriterule will no longer trigger for the css files for example).



来源:https://stackoverflow.com/questions/26233162/htaccess-resource-interpreted-as-script-but-transferred-with-mime-type-text-htm

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!