Javascript/jquery 在 mod_rewrite 开启时无法加载

Javascript/jquery does not load with mod_rewrite on

提问人:okey_on 提问时间:8/5/2014 最后编辑:okey_on 更新时间:8/5/2014 访问量:423

问:

我仍在为.所以我的测试页面请求在我打开之前运行良好。mod_rewritemod_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>

只需测试索引.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
javascript php . htaccess mod-rewrite unobtrusive-javascript

评论

0赞 jfriend00 8/5/2014
当您在浏览器中执行 View/Source 时,head 部分和任何相关脚本是什么样子的?在这里,您可以看到实际提供给浏览器的内容,以便您可以看到它实际上对您的文件执行了什么操作。
0赞 okey_on 8/5/2014
@jfriend00它与我上面介绍的相同。
0赞 jfriend00 8/5/2014
我会是你,这与你期望的不同,因为这就是错误所在。index.js

答:

1赞 wedi 8/5/2014 #1

如果您在规则之前使用

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

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

查看 http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html