Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/.htaccess/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/backbone.js/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
.htaccess 使用Backbone.js和/或htaccess重定向子目录_.htaccess_Backbone.js_Path_Rewrite_Router - Fatal编程技术网

.htaccess 使用Backbone.js和/或htaccess重定向子目录

.htaccess 使用Backbone.js和/或htaccess重定向子目录,.htaccess,backbone.js,path,rewrite,router,.htaccess,Backbone.js,Path,Rewrite,Router,经过数小时的研究和修补,我终于成功地使backbone.js路由正常工作,但有一个例外: 如果我输入“/workingdir/routepath”-一切都很好,它使用了“routpath”路径,但是如果我输入“/workingdir/routepath/”或“/workingdir/routepath/asdf”或任何类似的内容,我的网站就会崩溃,我会出现类似以下的错误: Resource interpreted as Stylesheet but transferred with MIME t

经过数小时的研究和修补,我终于成功地使backbone.js路由正常工作,但有一个例外: 如果我输入“/workingdir/routepath”-一切都很好,它使用了“routpath”路径,但是如果我输入“/workingdir/routepath/”或“/workingdir/routepath/asdf”或任何类似的内容,我的网站就会崩溃,我会出现类似以下的错误:

Resource interpreted as Stylesheet but transferred with MIME type text/html:  "http://example.com/staging/personal/css/style.css". fj:5
Resource interpreted as Script but transferred with MIME type text/html: "http://example.com/staging/personal/scripts/jquery-1.7.2.min.js". fj:6
Uncaught SyntaxError: Unexpected token < jquery-1.7.2.min.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://example.com/staging/personal/scripts/nav.js". fj:6
Resource interpreted as Script but transferred with MIME type text/html: "http://example.com/staging/personal/scripts/underscore-min.js". fj:6
Uncaught SyntaxError: Unexpected token < underscore-min.js:1
Resource interpreted as Script but transferred with MIME type text/html: "http://example.com/staging/personal/scripts/backbone-min.js". fj:6
Uncaught SyntaxError: Unexpected token < backbone-min.js:1
Uncaught SyntaxError: Unexpected token < 
资源被解释为样式表,但使用MIME类型text/html传输:http://example.com/staging/personal/css/style.css". 福建:5
解释为脚本但使用MIME类型text/html传输的资源:http://example.com/staging/personal/scripts/jquery-1.7.2.min.js". 福建:6
未捕获的语法错误:意外标记
而且页面没有任何样式。我认为问题来自URL中的斜杠,使css和js文件的路径指向错误的位置(它们应该位于“staging/css/”和“staging/scripts/”,但正如日志所示,它正在查找“staging/personal/xxx”)


有没有办法解决这个问题?谢谢你抽出时间

相对路径引用的解析方式将根据请求URI是否具有尾部斜杠而有所不同。我想这就是造成你问题的原因。考虑这些链接:

<!-- Relative path references -->

<link href="staging/css/style1.css">

<link href="./staging/css/style2.css">


<!-- Absolute path reference -->

<link href="/workingdir/staging/css/style3.css">

因此,如果您希望能够使用尾随斜杠或附加段发出请求,则需要使用绝对路径引用。

仅与有此问题的其他人共享。我也有同样的问题,但现在有了不同的解决方案。这些对.htaccess的添加最初不起作用:

AddType application/x-javascript .js
AddType text/css .css 
AddType text/javascript .js
AddType text/css .css
AddType font/ttf .ttf
AddType font/eot .eot
AddType font/otf .otf
AddType application/woff .woff
AddType font/woff .woff
AddType font/opentype .woff
AddType application/x-font-woff .woff
AddType application/vnd.ms-fontobject .eot
AddDefaultCharset UTF-8
Options -Indexes
最后,我意识到,虽然我下面的路径在localhost上工作,但区分大小写的服务器不接受该路径

\js\prettyPhoto\js\jquery.prettyPhoto.js
而不是

\js\prettyphoto\js\jquery.prettyPhoto.js
大写字母p犯了所有这些错误!对于您的情况,可能也是这样,因为您有“未捕获的语法错误:意外标记<”和“资源被解释为样式表,但使用MIME类型text/html传输:”


如果有帮助,请告诉我:)

如果示例路径尚未一致,请让它们一致好吗?例如,
workindir
是否对应于
staging
或其他内容?另外,
example.com
(或其亲属之一)通常是您在示例中寻找域名占位符的最佳选择。
\js\prettyphoto\js\jquery.prettyPhoto.js