Javascript / jquery不会加载mod_rewrite

时间:2014-08-05 01:42:35

标签: javascript php .htaccess mod-rewrite unobtrusive-javascript

我仍然在努力应对mod_rewrite的运作。所以我的测试页面请求运行良好,直到我打开mod_rewrite

这是.htaccess指令

RewriteRule     ^.*$    scripts/index.php

目标PHP文件包含以下内容:

<head>
    <script type="text/javascript" src="//code.jquery.com/jquery-1.11.0.min.js" ></script>
    <script type="text/javascript" src="/libraries/colorbox-master/jquery.colorbox-min.js" ></script>
    <script type="text/javascript" src="/js/index.js" ></script>
    <title>index.php</title>
</head>

只需测试index.js文件:

console.log('Hello world');

我在启用mod_rewrite的情况下收到此浏览器控制台错误消息:

Resource interpreted as Script but transferred with MIME type text/html: "http://web3.loc/js/index.js". index.php:7
Uncaught SyntaxError: Unexpected token <                    index.js:2

1 个答案:

答案 0 :(得分:1)

如果您在规则之前加上

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

如果请求现有文件或目录并且将提供所请求的资源而不是index.php,则不会对其进行评估。

请参阅http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html