drau67562 2014-08-05 01:42
浏览 53
已采纳

Javascript / jquery不会加载mod_rewrite

I'm still struggling with the workings of mod_rewrite. So my test page request works well until I turn on mod_rewrite.

This is the .htaccess directive

RewriteRule     ^.*$    scripts/index.php

And the target PHP file has these:

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

And just testing out the index.js file with:

console.log('Hello world');

I get this browser console error messages with mod_rewrite turned on:

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条回答 默认 最新

  • douzai8285 2014-08-05 01:50
    关注

    If you preceed your rule with

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

    it will not be evaluated if an existing file or directory is requested and the requested ressource will be served instead of your index.php.

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

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器