drau67562 2014-08-04 17: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-04 17: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

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

报告相同问题?

手机看
程序员都在用的中文IT技术交流社区

程序员都在用的中文IT技术交流社区

专业的中文 IT 技术社区,与千万技术人共成长

专业的中文 IT 技术社区,与千万技术人共成长

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

关注【CSDN】视频号,行业资讯、技术分享精彩不断,直播好礼送不停!

客服 返回
顶部